Java Code Examples for com.igormaznitsa.meta.common.utils.GetUtils#ensureNonNull()

The following examples show how to use com.igormaznitsa.meta.common.utils.GetUtils#ensureNonNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractGolangMojo.java    From mvn-golang with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static String extractComputerName() {
  String result = System.getenv("COMPUTERNAME");
  if (result == null) {
    result = System.getenv("HOSTNAME");
  }
  if (result == null) {
    try {
      result = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException ex) {
      result = null;
    }
  }
  return GetUtils.ensureNonNull(result, "<Unknown computer>");
}
 
Example 2
Source File: MavenUtils.java    From mvn-golang with Apache License 2.0 5 votes vote down vote up
/**
 * Make artifact record from a maven artifact
 *
 * @param artifact artifact to be converted into string, must not be null
 * @return string representation of artifact, must not be null
 * @see #parseArtifactRecord(java.lang.String,
 * org.apache.maven.artifact.handler.ArtifactHandler)
 */
@Nonnull
public static String makeArtifactRecord(@Nonnull final Artifact artifact) {
  return artifact.getGroupId() +
      "::" + artifact.getArtifactId() +
      "::" + artifact.getVersionRange().toString() +
      "::" + GetUtils.ensureNonNull(artifact.getScope(), "compile") +
      "::" + GetUtils.ensureNonNull(artifact.getType(), "zip") +
      "::" + GetUtils.ensureNonNull(artifact.getClassifier(), "");
}
 
Example 3
Source File: Topic.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Nonnull
public Topic makeChild(@Nullable final String text, @Nullable final Topic afterTheTopic) {
  this.map.lock();
  try {
    final Topic result = new Topic(this.map, this, GetUtils.ensureNonNull(text, "")); //NOI18N
    if (afterTheTopic != null && this.children.indexOf(afterTheTopic) >= 0) {
      result.moveAfter(afterTheTopic);
    }
    return result;
  } finally {
    this.map.unlock();
  }
}
 
Example 4
Source File: GolangTestMojo.java    From mvn-golang with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
@MustNotContainNull
public String[] getOptionalExtraTailArguments() {
  return GetUtils.ensureNonNull(this.testFlags, ArrayUtils.EMPTY_STRING_ARRAY);
}
 
Example 5
Source File: AbstractGolangMojo.java    From mvn-golang with Apache License 2.0 4 votes vote down vote up
@Nonnull
public Map<?, ?> getEnv() {
  return GetUtils.ensureNonNull(this.env, Collections.EMPTY_MAP);
}
 
Example 6
Source File: AbstractGolangMojo.java    From mvn-golang with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static String extractDomainName() {
  final String result = System.getenv("USERDOMAIN");
  return GetUtils.ensureNonNull(result, "");
}
 
Example 7
Source File: AbstractGolangMojo.java    From mvn-golang with Apache License 2.0 4 votes vote down vote up
protected void registerEnvVars(
    @Nonnull final ProcessExecutor result,
    @Nonnull final File theGoRoot,
    @Nullable final String theGoBin,
    @Nullable final String theGoCache,
    @Nonnull final File sourcesFile,
    @MustNotContainNull @Nonnull final File[] goPathParts
) throws IOException {
  logOptionally("....Environment vars....");

  addEnvVar(result, "GOROOT", theGoRoot.getAbsolutePath());
  this.project.getProperties().setProperty("mvn.golang.last.goroot", theGoRoot.getAbsolutePath());

  String preparedGoPath = IOUtils.makeOsFilePathWithoutDuplications(goPathParts);
  if (isEnforceGoPathToEnd()) {
    preparedGoPath = IOUtils.makeOsFilePathWithoutDuplications(makePathFromExtraGoPathElements(), removeSrcFolderAtEndIfPresented(sourcesFile.getAbsolutePath()), getSpecialPartOfGoPath(), preparedGoPath);
  } else {
    preparedGoPath = IOUtils.makeOsFilePathWithoutDuplications(preparedGoPath, makePathFromExtraGoPathElements(), removeSrcFolderAtEndIfPresented(sourcesFile.getAbsolutePath()), getSpecialPartOfGoPath());
  }
  addEnvVar(result, "GOPATH", preparedGoPath);
  this.project.getProperties().setProperty("mvn.golang.last.gopath", preparedGoPath);

  if (theGoBin == null) {
    getLog().warn("GOBIN is disabled by direct order");
  } else {
    addEnvVar(result, "GOBIN", theGoBin);
    this.project.getProperties().setProperty("mvn.golang.last.gobin", theGoBin);
  }

  if (theGoBin == null) {
    getLog().warn("GOCACHE is not provided by direct order");
  } else {
    addEnvVar(result, "GOCACHE", theGoCache);
    this.project.getProperties().setProperty("mvn.golang.last.gocache", theGoCache);
  }

  final String trgtOs = this.getTargetOS();
  final String trgtArch = this.getTargetArch();
  final String trgtArm = this.getTargetArm();
  final String trgt386 = this.getTarget386();

  if (trgt386 != null) {
    addEnvVar(result, "GO386", trgt386);
    this.project.getProperties().setProperty("mvn.golang.last.go386", trgt386);
  }

  if (trgtOs != null) {
    addEnvVar(result, "GOOS", trgtOs);
    this.project.getProperties().setProperty("mvn.golang.last.goos", trgtOs);
  }

  if (trgtArm != null) {
    addEnvVar(result, "GOARM", trgtArm);
    this.project.getProperties().setProperty("mvn.golang.last.goarm", trgtArm);
  }

  if (trgtArch != null) {
    addEnvVar(result, "GOARCH", trgtArch);
    this.project.getProperties().setProperty("mvn.golang.last.goarch", trgtArch);
  }

  final File gorootbootstrap = findGoRootBootstrap(true);
  if (gorootbootstrap != null) {
    addEnvVar(result, "GOROOT_BOOTSTRAP", gorootbootstrap.getAbsolutePath());
    this.project.getProperties().setProperty("mvn.golang.last.goroot_bootstrap", gorootbootstrap.getAbsolutePath());
  }

  String thePath = GetUtils.ensureNonNull(getEnvPath(), "");
  thePath = IOUtils.makeOsFilePathWithoutDuplications((theGoRoot + File.separator + getExecSubpath()), thePath, theGoBin);
  addEnvVar(result, "PATH", thePath);
  this.project.getProperties().setProperty("mvn.golang.last.path", thePath);

  boolean go111moduleDetected = false;

  for (final Map.Entry<?, ?> record : getEnv().entrySet()) {
    if (ENV_GO111MODULE.equals(record.getKey().toString())) {
      go111moduleDetected = true;
    }
    addEnvVar(result, record.getKey().toString(), record.getValue().toString());
  }

  if (this.isModuleMode()) {
    if (go111moduleDetected) {
      this.getLog().warn(String.format("Module mode is true but %s detected among custom environment parameters", ENV_GO111MODULE));
    } else {
      this.getLog().warn(String.format("Forcing '%s = on' because module mode is activated", ENV_GO111MODULE));
      addEnvVar(result, ENV_GO111MODULE, "on");
    }
  }
}
 
Example 8
Source File: AbstractGoPackageAwareMojo.java    From mvn-golang with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
@MustNotContainNull
public String[] getTailArguments() {
  return GetUtils.ensureNonNull(getPackages(), ArrayUtils.EMPTY_STRING_ARRAY);
}
 
Example 9
Source File: AbstractGoPackageAndDependencyAwareMojo.java    From mvn-golang with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
@MustNotContainNull
public String[] getTailArguments() {
  return GetUtils.ensureNonNull(getPackages(), ArrayUtils.EMPTY_STRING_ARRAY);
}
 
Example 10
Source File: GolangBuildMojo.java    From mvn-golang with Apache License 2.0 4 votes vote down vote up
public void setBuilMode(@Nullable final String buildMode) {
  this.buildMode = GetUtils.ensureNonNull(buildMode, "default");
}
 
Example 11
Source File: GolangCustomMojo.java    From mvn-golang with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public String getGoCommand() {
  return GetUtils.ensureNonNull(this.customCommand, "");
}
 
Example 12
Source File: MindMapPanelConfig.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
public void setRenderQuality(@Nullable final RenderQuality value) {
  this.renderQuality = GetUtils.ensureNonNull(value, Utils.getDefaultRenderQialityForOs());
  notifyCfgListenersAboutChange();
}
 
Example 13
Source File: MindmupExporter.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
private void writeTopic(
    @Nonnull final JSONStringer stringer,
    @Nonnull final MindMapPanelConfig cfg,
    @Nonnull final AtomicInteger idCounter,
    @Nullable final Topic topic,
    @Nonnull final Map<String, String> linkMap,
    @Nonnull final Map<String, TopicId> uuidMap
) {
  stringer.key("title").value(GetUtils.ensureNonNull(topic.getText(), ""));
  final int topicId = idCounter.getAndIncrement();
  stringer.key("id").value(topicId);

  final String uuid = GetUtils.ensureNonNull(topic.getAttribute(ExtraTopic.TOPIC_UID_ATTR), "genlink_" + topicId);
  uuidMap.put(uuid, new TopicId(topicId, uuid, topic));

  final ExtraNote note = (ExtraNote) topic.getExtras().get(Extra.ExtraType.NOTE);
  final ExtraTopic jump = (ExtraTopic) topic.getExtras().get(Extra.ExtraType.TOPIC);
  final ExtraLink link = (ExtraLink) topic.getExtras().get(Extra.ExtraType.LINK);
  final ExtraFile file = (ExtraFile) topic.getExtras().get(Extra.ExtraType.FILE);

  final String encodedImage = topic.getAttribute(ATTR_KEY);

  if (jump != null) {
    linkMap.put(uuid, jump.getValue());
  }

  stringer.key("attr").object();

  stringer.key("style").object();
  stringer.key("background").value(Utils.color2html(MindMapUtils.getBackgroundColor(cfg, topic), false));
  stringer.endObject();

  if (note != null) {
    stringer.key("note").object();
    stringer.key("index").value(3);
    stringer.key("text").value(note.getValue());
    stringer.endObject();
  }

  if (encodedImage != null) {
    BufferedImage renderedImage;
    try {
      renderedImage = ImageIO.read(new ByteArrayInputStream(Utils.base64decode(encodedImage)));
    } catch (IOException ex) {
      LOGGER.error("Can't render image for topic:" + topic);
      renderedImage = null;
    }

    stringer.key("icon").object();
    stringer.key("url").value("data:image/png;base64," + encodedImage);
    stringer.key("position").value("left");

    if (renderedImage != null) {
      stringer.key("width").value(renderedImage.getWidth());
      stringer.key("height").value(renderedImage.getHeight());
    }

    stringer.endObject();
  }

  stringer.endObject();

  if (link != null || file != null) {
    stringer.key("attachment").object();
    stringer.key("contentType").value("text/html");
    stringer.key("content").value(makeHtmlFromExtras(link, file));
    stringer.endObject();
  }

  stringer.key("ideas").object();
  int childIdCounter = 1;
  for (final Topic child : topic.getChildren()) {
    final boolean left = AbstractCollapsableElement.isLeftSidedTopic(child);
    stringer.key(Integer.toString(left ? -childIdCounter : childIdCounter)).object();
    childIdCounter++;
    writeTopic(stringer, cfg, idCounter, child, linkMap, uuidMap);
    stringer.endObject();
  }
  stringer.endObject();
}