Java Code Examples for org.netbeans.api.java.platform.JavaPlatform#isValid()

The following examples show how to use org.netbeans.api.java.platform.JavaPlatform#isValid() . 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: ProjectProblemsProviders.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static boolean existPlatform(
        @NullAllowed final Project prj,
        @NonNull final PropertyEvaluator eval,
        @NonNull final String platform) {
    if (platform.equals("default_platform")) { // NOI18N
        return true;
    }
    for (JavaPlatform plat : JavaPlatformManager.getDefault().getInstalledPlatforms()) {
        // XXX: this should be defined as PROPERTY somewhere
        if (platform.equals(plat.getProperties().get(PLAT_PROP_ANT_NAME))) {
            return plat.isValid();
        }
    }
    return prj == null ?
            false :
            ProjectPlatform.forProject(prj, eval, "j2se") != null;   //NOI18N    //Todo: custom platform type?
}
 
Example 2
Source File: PlatformNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public String getHtmlDisplayName () {
    final Pair<String,JavaPlatform> platHolder = pp.getPlatform();
    if (platHolder == null) {
        return null;
    }
    final JavaPlatform jp = platHolder.second();
    if (jp == null || !jp.isValid()) {
        String displayName = this.getDisplayName();
        try {
            displayName = XMLUtil.toElementContent(displayName);
        } catch (CharConversionException ex) {
            // OK, no annotation in this case
            return null;
        }
        return "<font color=\"#A40000\">" + displayName + "</font>"; //NOI18N
    } else {
        return null;
    }
}
 
Example 3
Source File: PreferredProjectPlatform.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a preferred {@link JavaPlatform} for a new project.
 * @param platformType the platform type as specified by {@link Specification#getName()}
 * @return the preferred {@link JavaPlatform}
 */
@CheckForNull
public static JavaPlatform getPreferredPlatform(@NonNull final String platformType) {
    Parameters.notNull("platformType", platformType);   //NOI18N
    final String platformId = NbPreferences.forModule(PreferredProjectPlatform.class).get(
            MessageFormat.format(PREFERRED_PLATFORM, platformType),
            null);
    final JavaPlatformManager jpm = JavaPlatformManager.getDefault();
    if (platformId != null) {
        for (JavaPlatform jp : jpm.getInstalledPlatforms()) {
            if (platformId.equals(jp.getProperties().get(PLATFORM_ANT_NAME)) &&
                platformType.equals(jp.getSpecification().getName()) &&
                jp.isValid()) {
                return jp;
            }
        }
    }
    final JavaPlatform defaultPlatform = jpm.getDefaultPlatform();
    return platformType.equals(defaultPlatform.getSpecification().getName())?
           defaultPlatform:
           null;
}
 
Example 4
Source File: BootCPNodeFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public String getDisplayName() {
    final Pair<String, JavaPlatform> platHolder = pp.getPlatform();
    if (platHolder == null) {
        return Bundle.TXT_UnknownPlatform();
    }
    String name;
    final JavaPlatform jp = platHolder.second();
    if (jp != null) {
        if (jp.isValid()) {
            name = jp.getDisplayName();
        } else {
            name = Bundle.FMT_BrokenPlatform(jp.getDisplayName());
        }
    } else {
        String platformId = platHolder.first();
        if (platformId == null) {
            name = Bundle.TXT_BrokenPlatform();
        } else {
            name = Bundle.FMT_BrokenPlatform(platformId);
        }
    }
    return name;
}
 
Example 5
Source File: BootCPNodeFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public String getHtmlDisplayName() {
    final Pair<String, JavaPlatform> platHolder = pp.getPlatform();
    if (platHolder == null) {
        return null;
    }
    final JavaPlatform jp = platHolder.second();
    if (jp == null || !jp.isValid()) {
        String displayName = this.getDisplayName();
        try {
            displayName = XMLUtil.toElementContent(displayName);
        } catch (CharConversionException ex) {
            // OK, no annotation in this case
            return null;
        }
        return "<font color=\"#A40000\">" + displayName + "</font>"; //NOI18N
    } else {
        return null;
    }
}
 
Example 6
Source File: PlatformNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public String getDisplayName () {
    final Pair<String,JavaPlatform> platHolder = pp.getPlatform();
    if (platHolder == null) {
        return NbBundle.getMessage(PlatformNode.class, "TXT_UnknownPlatform");
    }
    String name;
    final JavaPlatform jp = platHolder.second();
    if (jp != null) {
        if (jp.isValid()) {
            name = jp.getDisplayName();
        } else {
            name = MessageFormat.format(
                    NbBundle.getMessage(PlatformNode.class,"FMT_BrokenPlatform"),
                    new Object[] {
                        jp.getDisplayName()
                    });
        }
    } else {
        String platformId = platHolder.first();
        if (platformId == null) {
            name = NbBundle.getMessage(PlatformNode.class,"TXT_BrokenPlatform");
        } else {
            name = MessageFormat.format(
                    NbBundle.getMessage(PlatformNode.class,"FMT_BrokenPlatform"),
                    new Object[] {
                        platformId
                    });
        }
    }
    return name;
}
 
Example 7
Source File: GradleDaemonExecutor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void printCommandLine() {
    StringBuilder commandLine = new StringBuilder(1024);

    String userHome = GradleSettings.getDefault().getPreferences().get(GradleSettings.PROP_GRADLE_USER_HOME, null);
    if (userHome != null) {
        commandLine.append("GRADLE_USER_HOME=\"").append(userHome).append("\"\n"); //NOI18N
    }
    JavaPlatform activePlatform = RunUtils.getActivePlatform(config.getProject()).second();
    if ((activePlatform != null) && activePlatform.isValid() && !activePlatform.getInstallFolders().isEmpty()) {
        File javaHome = FileUtil.toFile(activePlatform.getInstallFolders().iterator().next());
        commandLine.append("JAVA_HOME=\"").append(javaHome.getAbsolutePath()).append("\"\n"); //NOI18N
    }
    File dir = FileUtil.toFile(config.getProject().getProjectDirectory());
    if (dir != null) {
        commandLine.append("cd ").append(dir.getAbsolutePath()).append("; "); //NOI18N
    }

    GradleBaseProject gbp = GradleBaseProject.get(config.getProject());
    if (gbp != null
            && new GradleFiles(gbp.getProjectDir(), true).hasWrapper()
            && GradleSettings.getDefault().isWrapperPreferred()) {

            Path rootPath = gbp.getRootDir().toPath();
            Path projectPath = gbp.getProjectDir().toPath();

            String relRoot = projectPath.relativize(rootPath).toString();
            relRoot = relRoot.isEmpty() ? "." : relRoot;
            commandLine.append(relRoot).append("/gradlew"); //NOI18N
        } else {
            File gradleDistribution = RunUtils.evaluateGradleDistribution(null, false);
            if (gradleDistribution != null) {
                File gradle = new File(gradleDistribution, "bin/gradle"); //NOI18N
                commandLine.append(gradle.getAbsolutePath());
            }
        }

    for (String arg : config.getCommandLine().getSupportedCommandLine()) {
        commandLine.append(' ');
        if (arg.contains(" ") || arg.contains("*")) { //NOI18N
            commandLine.append('\'').append(arg).append('\'');
        } else {
            commandLine.append(arg);
        }
    }
    commandLine.append('\n');
    try {
        if (IOColorPrint.isSupported(io)) {
            IOColorPrint.print(io, commandLine, IOColors.getColor(io, IOColors.OutputType.INPUT));
        } else {
            io.getOut().print(commandLine);
        }
    } catch (IOException ex) {
        // Shall not happen...
    }
}