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

The following examples show how to use org.netbeans.api.java.platform.JavaPlatform#getDefault() . 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: J2SEPlatformJavadocForBinaryQueryTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testQuery() throws Exception {
    JavaPlatform platform = JavaPlatform.getDefault();
    ClassPath cp = platform.getBootstrapLibraries();
    FileObject pfo = cp.getRoots()[0];
    URL u = URLMapper.findURL(pfo, URLMapper.EXTERNAL);
    URL urls[] = JavadocForBinaryQuery.findJavadoc(u).getRoots();
    assertEquals(1, urls.length);
    assertTrue(urls[0].toString(), urls[0].toString().startsWith("https://docs.oracle.com/"));

    List<URL> l = new ArrayList<URL>();
    File javadocFile = getBaseDir();
    File api = new File (javadocFile,"api");
    File index = new File (api,"index-files");
    FileUtil.toFileObject(index);
    index.mkdirs();
    l.add(Utilities.toURI(javadocFile).toURL());
    J2SEPlatformImpl platformImpl = (J2SEPlatformImpl)platform;
    platformImpl.setJavadocFolders(l);
    urls = JavadocForBinaryQuery.findJavadoc(u).getRoots();
    assertEquals(1, urls.length);
    assertEquals(Utilities.toURI(api).toURL(), urls[0]);
}
 
Example 2
Source File: JavaPlatformsComboBox.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Set selected item in the combo box display area to the provided Java SE
 * platform.
 * <p/>
 * @param platform Java SE platform to be set as selected. Default platform
 *                 will be used when <code>null</code> value is supplied.
 */
@Override
public void setSelectedItem(Object platform) {
    if (platform == null) {
        platform = JavaPlatform.getDefault();
    }
    if (platform instanceof JavaPlatform) {
        int i, count = dataModel.getSize();
        for (i = 0; i < count; i++) {
            if (((JavaPlatform) platform).getDisplayName().equals(
                    (dataModel.getElementAt(i))
                    .getPlatform().getDisplayName())) {
                super.setSelectedItem(dataModel.getElementAt(i));
                break;
            }
        }
    } else {
        super.setSelectedItem(platform);
    }
}
 
Example 3
Source File: GrailsProjectConfig.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public JavaPlatform getJavaPlatform() {
    String platformId;
    synchronized (settings) {
        platformId = settings.getJavaPlatformForProject(prj);
    }

    if (platformId == null) {
        return JavaPlatform.getDefault();
    }

    JavaPlatform[] platforms = PLATFORM_MANAGER.getPlatforms(null, new Specification("j2se", null)); //NOI18N
    for (JavaPlatform platform : platforms) {
        if (platform.getInstallFolders().size() > 0) {
            String antName = platform.getProperties().get("platform.ant.name"); //NOI18N
            if (platformId.equals(antName)) {
                return platform;
            }
        }
    }
    return JavaPlatform.getDefault();
}
 
Example 4
Source File: JavaPlatformsComboBox.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Set selected item in the combo box display area to the provided Java SE
 * platform.
 * <p/>
 * @param platform Java SE platform to be set as selected. Default platform
 *                 will be used when <code>null</code> value is supplied.
 */
@Override
public void setSelectedItem(Object platform) {
    if (platform == null) {
        platform = JavaPlatform.getDefault();
    }
    if (platform instanceof JavaPlatform) {
        int i, count = dataModel.getSize();
        for (i = 0; i < count; i++) {
            if (((JavaPlatform) platform).getDisplayName().equals(
                    (dataModel.getElementAt(i))
                    .getPlatform().getDisplayName())) {
                super.setSelectedItem(dataModel.getElementAt(i));
                break;
            }
        }
    } else {
        super.setSelectedItem(platform);
    }
}
 
Example 5
Source File: ModuleProperties.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static JavaPlatform findJavaPlatformByLocation(String home) {
    if (home == null) {
        return JavaPlatform.getDefault();
    }
    for (JavaPlatform platform : JavaPlatformManager.getDefault().getInstalledPlatforms()) {
        if (new File(home).equals(getPlatformLocation(platform))) {
            return platform;
        }
    }
    return null;
}
 
Example 6
Source File: StartTomcat.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JavaPlatform getJavaPlatform() {
    JavaPlatform platform = tm.getTomcatProperties().getJavaPlatform();
    if (platform.getInstallFolders().size() <= 0) {
        LOGGER.log(Level.INFO, "The Java Platform used by Tomcat is broken; using the default one");
        return JavaPlatform.getDefault();
    }
    return platform;
}
 
Example 7
Source File: ModuleProperties.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static JavaPlatform findJavaPlatformByID(String id) {
    if (id == null || id.equals("default")) { // NOI18N
        return JavaPlatform.getDefault();
    }
    JavaPlatform[] platforms = JavaPlatformManager.getDefault().getInstalledPlatforms();
    for (int i = 0; i < platforms.length; i++) {
        if (id.equals(getPlatformID(platforms[i]))) {
            return platforms[i];
        }
    }
    return null;
}
 
Example 8
Source File: ProjectFactorySupportTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testUpdateProjectClassPath() throws IOException {
    EclipseProject eclipse = getTestableProject(1, getWorkDir());
    File prj = new File(getWorkDirPath(), "nb");
    // create required project
    AntProjectHelper helper0 = J2SEProjectGenerator.createProject(
            new File(prj, "JavaLibrary1"), "JavaLibrary1", new File[0], new File[0], null, null, null);
    Project p0 = ProjectManager.getDefault().findProject(helper0.getProjectDirectory());
    AntProjectHelper helper00 = J2SEProjectGenerator.createProject(
            new File(prj, "jlib"), "jlib", new File[0], new File[0], null, null, null);
    Project p00 = ProjectManager.getDefault().findProject(helper00.getProjectDirectory());
    ProjectImportModel model = new ProjectImportModel(eclipse, new File(prj, "test"),
            JavaPlatform.getDefault(), Arrays.<Project>asList(new Project[]{p0, p00}));
    final AntProjectHelper helper = J2SEProjectGenerator.createProject(
            new File(prj, "test"), "test", model.getEclipseSourceRootsAsFileArray(), 
            model.getEclipseTestSourceRootsAsFileArray(), null, null, null);
    J2SEProject p = (J2SEProject)ProjectManager.getDefault().findProject(helper.getProjectDirectory());
    List<String> importProblems = new ArrayList<String>();
    ProjectFactorySupport.updateProjectClassPath(helper, p.getReferenceHelper(), model, importProblems);
    EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
    assertEquals(
        "${file.reference.commons-cli-1.0.jar}:" +
        "${file.reference.ejb3-persistence.jar}:" +
        "${reference.JavaLibrary1.jar}", 
        ep.getProperty("javac.classpath").replace(';', ':'));
    assertEquals("${var.MAVEN_REPOPO}/commons-cli/commons-cli/1.0/commons-cli-1.0.jar",
            ep.getProperty("file.reference.commons-cli-1.0.jar"));
}
 
Example 9
Source File: ProjectFactorySupportTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCalculateKey() throws IOException {
    EclipseProject eclipse = getTestableProject(1, getWorkDir());
    ProjectImportModel model = new ProjectImportModel(eclipse, new File(getWorkDirPath(), "nb"), JavaPlatform.getDefault(), Collections.<Project>emptyList());
    String expResult = 
        "src=src;" +
        "src=test;" +
        "var=MAVEN_REPOPO/commons-cli/commons-cli/1.0/commons-cli-1.0.jar;" +
        "file=/home/dev/hibernate-annotations-3.3.1.GA/lib/ejb3-persistence.jar;" +
        "prj=JavaLibrary1;"+
        "jre="+JavaPlatform.getDefault().getDisplayName()+";";
    String result = ProjectFactorySupport.calculateKey(model);
    assertEquals(expResult, result);
}
 
Example 10
Source File: GradleFileLocator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ClassPath getProjectClasspath(Project p) {
    ClassPath result;
    ClassPathProvider cpp = p.getLookup().lookup(ClassPathProvider.class);
    Set<FileObject> roots = new HashSet<>();
    Sources sources = ProjectUtils.getSources(p);
    if (sources != null) {
        SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        for (SourceGroup group : groups) {
            roots.add(group.getRootFolder());
        }
    }

    Set<ClassPath> setCP = new HashSet<>();
    if (cpp != null) {
        for (FileObject file : roots) {
            ClassPath path = cpp.findClassPath(file, ClassPath.COMPILE);
            setCP.add(path);
        }
    }

    for (ClassPath cp : setCP) {
        FileObject[] rootsCP = cp.getRoots();
        for (FileObject fo : rootsCP) {
            FileObject[] aaa = SourceForBinaryQuery.findSourceRoots(fo.toURL()).getRoots();
            roots.addAll(Arrays.asList(aaa));
        }
    }
    //TODO: Use something more specific in the future Ticket #81
    JavaPlatform platform = JavaPlatform.getDefault();

    if (platform != null) {
        roots.addAll(Arrays.asList(platform.getSourceFolders().getRoots()));
    }
    result = ClassPathSupport.createClassPath(roots.toArray(new FileObject[roots.size()]));
    return result;
}
 
Example 11
Source File: JBStartRunnable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JavaPlatform getJavaPlatform(JBProperties properties) {
    JavaPlatform platform = properties.getJavaPlatform();
    if (platform.getInstallFolders().size() <= 0) {
        LOGGER.log(Level.INFO, "The Java Platform used by JBoss is broken; using the default one");
        return JavaPlatform.getDefault();
    }
    return platform;
}
 
Example 12
Source File: ShellOptions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public JavaPlatform getDefaultPlatform() {
    JavaPlatform check = JavaPlatform.getDefault();
    if (check.getSpecification().getVersion().compareTo(MIN_SPEC_VERSION) >= 0) {
        return check;
    }
    JavaPlatform[] candidates = JavaPlatformManager.getDefault().getPlatforms(null, 
        new Specification("J2SE", MIN_SPEC_VERSION));
    return candidates == null || candidates.length == 0 ? null : candidates[0];
}
 
Example 13
Source File: FindUsagesJDK9Test.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Set-up the services and project
 */
@Override
protected void setUp() throws Exception {
    clearWorkDir();
    String work = getWorkDirPath();
    System.setProperty("netbeans.user", work);

    JavacParser.DISABLE_SOURCE_LEVEL_DOWNGRADE = true;

    //set -source 9 for the test project
    origSourceLevel = setSourceLevel("9");

    //ensure the default platform is "modular":
    ClassPath moduleBoot = BootClassPathUtil.getModuleBootPath();
    JavaPlatform defaultPlatform = JavaPlatform.getDefault();
    Field bootstrapField = J2SEPlatformImpl.class.getDeclaredField("bootstrap");
    bootstrapField.setAccessible(true);
    bootstrapField.set(defaultPlatform, new SoftReference<ClassPath>(moduleBoot) {
        @Override
        public ClassPath get() {
            return moduleBoot;
        }
    });

    projectDir = Utilities.openProject("SimpleJ2SEApp", getDataDir());
    SourceUtils.waitScanFinished();
}
 
Example 14
Source File: Utilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public synchronized ClasspathInfo createUniversalCPInfo() {
    Reference<ClasspathInfo> r = cached;
    if (r != null) {
        ClasspathInfo c = r.get();
        if (c != null) {
            return c;
        }
    }
    JavaPlatform select = JavaPlatform.getDefault();
    final JavaPlatformManager man = JavaPlatformManager.getDefault();
    if (select.getSpecification().getVersion() != null) {
        for (JavaPlatform p : JavaPlatformManager.getDefault().getInstalledPlatforms()) {
            if (!"j2se".equals(p.getSpecification().getName()) || p.getSpecification().getVersion() == null) continue;
            if (p.getSpecification().getVersion().compareTo(select.getSpecification().getVersion()) > 0) {
                select = p;
            }
        }
    }
    final ClasspathInfo result = new ClasspathInfo.Builder(select.getBootstrapLibraries())
                                                  .setModuleBootPath(select.getBootstrapLibraries())
                                                  .build();
    if (cached != null) {
            this.cached = new WeakReference<>(result);
    }
    if (weakL == null) {
        man.addPropertyChangeListener(weakL = WeakListeners.propertyChange(this, man));
    }
    return result;
}
 
Example 15
Source File: ProjectModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method returning source level of the current platform.
 */
public static String getDefaultSourceLevel() {
    JavaPlatform platform = JavaPlatform.getDefault();
    SpecificationVersion sv = platform.getSpecification().getVersion();
    if (sv.compareTo(JDK_MAX_SUPPORTED_VERSION)>0) {
        sv = JDK_MAX_SUPPORTED_VERSION;
    }
    return sv.toString();
}
 
Example 16
Source File: CtSymArchiveTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCtSym() throws Exception {
    final JavaPlatform jp = JavaPlatform.getDefault();
    assertNotNull(jp);
    if (jp.getInstallFolders().iterator().next().getFileObject("lib/modules") != null) {
        //the semantics of ct.sym is changed since JDK 9, disable this test for now:
        log("Running on JDK 9+, passed vacuously.");  //NOI18N
        return ;
    }
    final FileObject ctSym = jp.getInstallFolders().iterator().next().getFileObject("lib/ct.sym");  //NOI18N
    if (ctSym == null) {
        log(String.format("No ct.sym for platform: %s installed in: %s",jp.getDisplayName(), jp.getInstallFolders()));  //NOI18N
        return;
    }
    final ClassPath boot = jp.getBootstrapLibraries();
    assertNotNull(boot);
    FileObject base = null;
    for (FileObject root : boot.getRoots()) {
        if (root.getFileObject("java/lang/Object.class") != null) { //NOI18N
            base = root;
            break;
        }
    }
    assertNotNull(base);
    final Map<String,List<String>> ctContent = createMap(ctSym, "META-INF/sym/rt.jar/");
    final Map<String,List<String>> baseContent = createMap(FileUtil.getArchiveFile(base), null);
    final Archive arch = CachingArchiveProvider.getDefault().getArchive(
            base.toURL(),
            true);
    assertNotNull(arch);
    for (Map.Entry<String,List<String>> e : baseContent.entrySet()) {
        final String folder = e.getKey();
        List<String> folderContent = ctContent.get(folder);
        if (folderContent == null) {
            folderContent = e.getValue();
        }
        final List<String> archContent = asList(arch.getFiles(folder, null, EnumSet.of(JavaFileObject.Kind.CLASS), null, false));
        compare(folderContent,archContent);
    }
}
 
Example 17
Source File: ClassNameList.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
    if (classpathInfo == null) {
        Set<ClassPath> cpPaths = new HashSet<>(GlobalPathRegistry.getDefault().getPaths(ClassPath.COMPILE));
        Set<ClassPath> bootPaths = new HashSet<>(GlobalPathRegistry.getDefault().getPaths(ClassPath.BOOT));
        Set<ClassPath> sourcePaths = GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE);

        JavaPlatform p = JavaPlatform.getDefault();
        if (p != null) {
            bootPaths.add(p.getBootstrapLibraries());
            cpPaths.add(p.getStandardLibraries());
        }

        ClassPath compPath = ClassPathSupport.createProxyClassPath(cpPaths.toArray(new ClassPath[cpPaths.size()]));
        ClassPath bootPath = ClassPathSupport.createProxyClassPath(bootPaths.toArray(new ClassPath[bootPaths.size()]));
        ClassPath sourcePath = ClassPathSupport.createProxyClassPath(sourcePaths.toArray(new ClassPath[sourcePaths.size()]));
        
        classpathInfo = ClasspathInfo.create(bootPath, compPath, sourcePath);
    }
    ElementHandle<TypeElement> handle;
    
    try {
        try {
            ParserManager.parse("text/x-java", new ClasspathInfoTask(classpathInfo) { // NOI18N
                @Override
                public void run(ResultIterator resultIterator) throws Exception {
                    if (controller != null) {
                        return;
                    }
                    Parser.Result res = resultIterator.getParserResult();
                    CompilationController ctrl = CompilationController.get(res);
                    if (ctrl != null) {
                        controller = ctrl;
                        return;
                    }
                    for (Embedding e : resultIterator.getEmbeddings()) {
                        run(resultIterator.getResultIterator(e));
                        if (controller != null) {
                            return;
                        }
                    }
                }
            });
            if (controller == null) {
                // eeee ?
                return;
            }
        } catch (ParseException ex) {
            Exceptions.printStackTrace(ex);
        }
        handle = TypeElementFinder.find(classpathInfo, customizer);
    } finally {
        controller = null;
    }
    if (handle == null) {
        return;
    }
    insertRow(handle.getQualifiedName(), true);
}
 
Example 18
Source File: JDKSetupTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Checks version of default JavaPlatform JDK and sets
 * JDKpre6, JDK7u4to5, JDKpre7u6, JDKOSType and versionChecked
 */
public void checkJDKVersion() {
    if(!versionChecked) {
        JavaPlatform platform = JavaPlatform.getDefault();
        FileObject javaFO = platform.findTool("java");
        try {
            String commandLine = javaFO.getPath() + " -version";
            System.out.println("Executing " + commandLine);
            Process proc = Runtime.getRuntime().exec(commandLine);
            BufferedReader bri = new BufferedReader(new InputStreamReader(proc.getInputStream()));
            BufferedReader bre = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
            String line;
            while ((line = bri.readLine()) != null) {
                System.out.println("Log: " + line);
                checkLineForVersion(line);
            }
            bri.close();
            while ((line = bre.readLine()) != null) {
                System.out.println("Log: " + line);
                checkLineForVersion(line);
            }
            bre.close();
            String sysName = System.getProperty("os.name");
            JDKOSType = OSType.UNIX;
            if(sysName.toLowerCase().contains("win")) {
                JDKOSType = OSType.WINDOWS;
            } else {
                if(sysName.toLowerCase().contains("mac")) {
                    JDKOSType = OSType.MAC;
                }
            }
            proc.waitFor();
            if(!JDKpre16 && !JDKpre7u6) {
                System.out.println(TEST_RESULT + "Found JDK 7u6 or later.\nFX SDK assumed integrated into JDK directory structure.");
            } else {
                if(!JDKpre16 && JDKOSType == OSType.MAC && JDK7u4to5) {
                    System.out.println(TEST_RESULT + "Found Mac JDK 7u4 or 7u5.\nFX SDK assumed integrated into JDK directory structure.\nWebStart and FX browser plugins assumed to be missing.");
                } else {
                    System.out.println(TEST_RESULT + "Found JDK without integrated FX SDK.");
                }
            }
            versionChecked = true;
        }
        catch (Exception err) {
            System.err.println("Exception thrown while executing java.exe; " + err.getMessage());
        }
    }
}
 
Example 19
Source File: ProjectFactorySupportTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testSynchronizeProjectClassPath() throws IOException {
    // ================= start of copy of testUpdateProjectClassPath
    EclipseProject eclipse = getTestableProject(1, getWorkDir());
    File prj = new File(getWorkDirPath(), "nb");
    // create required project
    AntProjectHelper helper0 = J2SEProjectGenerator.createProject(
            new File(prj, "JavaLibrary1"), "JavaLibrary1", new File[0], new File[0], null, null, null);
    Project p0 = ProjectManager.getDefault().findProject(helper0.getProjectDirectory());
    AntProjectHelper helper00 = J2SEProjectGenerator.createProject(
            new File(prj, "jlib"), "jlib", new File[0], new File[0], null, null, null);
    Project p00 = ProjectManager.getDefault().findProject(helper00.getProjectDirectory());
    ProjectImportModel model = new ProjectImportModel(eclipse, new File(prj, "test"),
            JavaPlatform.getDefault(), Arrays.<Project>asList(new Project[]{p0, p00}));
    final AntProjectHelper helper = J2SEProjectGenerator.createProject(
            new File(prj, "test"), "test", model.getEclipseSourceRootsAsFileArray(), 
            model.getEclipseTestSourceRootsAsFileArray(), null, null, null);
    J2SEProject p = (J2SEProject)ProjectManager.getDefault().findProject(helper.getProjectDirectory());
    List<String> importProblems = new ArrayList<String>();
    ProjectFactorySupport.updateProjectClassPath(helper, p.getReferenceHelper(), model, importProblems);
    EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
    assertEquals(
        "${file.reference.commons-cli-1.0.jar}:" +
        "${file.reference.ejb3-persistence.jar}:" +
        "${reference.JavaLibrary1.jar}", 
        ep.getProperty("javac.classpath").replace(';', ':'));
    // ================= end of copy of testUpdateProjectClassPath
    
    String oldKey = ProjectFactorySupport.calculateKey(model);
    assertEquals(
        "src=src;" +
        "src=test;" +
        "var=MAVEN_REPOPO/commons-cli/commons-cli/1.0/commons-cli-1.0.jar;" +
        "file=/home/dev/hibernate-annotations-3.3.1.GA/lib/ejb3-persistence.jar;" +
        "prj=JavaLibrary1;"+
        "jre="+JavaPlatform.getDefault().getDisplayName()+";", oldKey);
    
    // add some items to classpath:
    eclipse = getTestableProject(2, getWorkDir());
    model = new ProjectImportModel(eclipse, new File(prj, "test"),
            JavaPlatform.getDefault(), Arrays.<Project>asList(new Project[]{p0, p00}));
    String newKey = ProjectFactorySupport.calculateKey(model);
    assertEquals("src=src;" +
        "src=test;" +
        "var=MAVEN_REPOPO/commons-cli/commons-cli/1.0/commons-cli-1.0.jar;" +
        "var=MAVEN_REPOPO/some/other.jar;" +
        "file=/home/dev/hibernate-annotations-3.3.1.GA/lib/ejb3-persistence.jar;" +
        "file=/some/other.jar;" +
        "ant=libs.david.classpath;" +
        "prj=JavaLibrary1;" +
        "prj=jlib;"+
        "jre="+JavaPlatform.getDefault().getDisplayName()+";", newKey);
    ProjectFactorySupport.synchronizeProjectClassPath(p, helper, p.getReferenceHelper(), model, oldKey, newKey, importProblems);
    ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
    assertEquals(
        "${file.reference.commons-cli-1.0.jar}:" +
        "${file.reference.ejb3-persistence.jar}:" +
        "${reference.JavaLibrary1.jar}:" +
        "${file.reference.other.jar}:" +
        "${file.reference.other.jar-1}:" +
        "${libs.david.classpath}:" +
        "${reference.jlib.jar}", 
        ep.getProperty("javac.classpath").replace(';', ':'));
    assertEquals("${var.MAVEN_REPOPO}/commons-cli/commons-cli/1.0/commons-cli-1.0.jar",
            ep.getProperty("file.reference.commons-cli-1.0.jar"));
    assertEquals("${var.MAVEN_REPOPO}/some/other.jar",
            ep.getProperty("file.reference.other.jar"));
    
    oldKey = newKey;
    // remove some items from classpath:
    eclipse = getTestableProject(3, getWorkDir());
    model = new ProjectImportModel(eclipse, new File(prj, "test"),
            JavaPlatform.getDefault(), Arrays.<Project>asList(new Project[]{p0, p00}));
    newKey = ProjectFactorySupport.calculateKey(model);
    assertEquals("src=src;" +
        "src=test;" +
        "var=MAVEN_REPOPO/some/other.jar;" +
        "file=/some/other.jar;" +
        "ant=libs.david.classpath;" +
        "prj=jlib;"+
        "jre="+JavaPlatform.getDefault().getDisplayName()+";", newKey);
    ProjectFactorySupport.synchronizeProjectClassPath(p, helper, p.getReferenceHelper(), model, oldKey, newKey, importProblems);
    ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
    assertEquals(
        "${file.reference.other.jar}:" +
        "${file.reference.other.jar-1}:" +
        "${libs.david.classpath}:" +
        "${reference.jlib.jar}", 
        ep.getProperty("javac.classpath").replace(';', ':'));
    assertNull(ep.getProperty("file.reference.commons-cli-1.0.jar"));
    assertEquals("${var.MAVEN_REPOPO}/some/other.jar",
            ep.getProperty("file.reference.other.jar"));
}
 
Example 20
Source File: ModuleProperties.java    From netbeans with Apache License 2.0 4 votes vote down vote up
static void storeJavaPlatform(AntProjectHelper helper, PropertyEvaluator eval, JavaPlatform platform, boolean isNetBeansOrg) throws IOException {
    if (isNetBeansOrg) {
        final boolean isDefault = platform == null || platform == JavaPlatform.getDefault();
        final File home = isDefault ? null : getPlatformLocation(platform);
        if (home != null || isDefault) {
            final FileObject nbbuild = helper.resolveFileObject(eval.evaluate("${nb_all}/nbbuild")); // NOI18N
            if (nbbuild != null) {
                try {
                    ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
                        public Void run() throws IOException {
                            FileObject userBuildProperties = nbbuild.getFileObject("user.build.properties"); // NOI18N
                            if (userBuildProperties == null) {
                                userBuildProperties = nbbuild.createData("user.build.properties"); // NOI18N
                            }
                            EditableProperties ep = Util.loadProperties(userBuildProperties);
                            if (isDefault) {
                                // Have to remove it; no default value.
                                ep.remove("nbjdk.home");
                            } else {
                                ep.setProperty("nbjdk.home", home.getAbsolutePath());
                            }
                            Util.storeProperties(userBuildProperties, ep);
                            return null;
                        }
                    });
                } catch (MutexException e) {
                    throw (IOException) e.getException();
                }
            }
        }
    } else {
        EditableProperties props = helper.getProperties(NbModuleProjectGenerator.PLATFORM_PROPERTIES_PATH);
        if (platform == null || platform == JavaPlatform.getDefault()) {
            if (props.containsKey(JAVA_PLATFORM_PROPERTY)) {
                // Could also just remove it, but probably nicer to set it explicitly to 'default'.
                props.put(JAVA_PLATFORM_PROPERTY, "default"); // NOI18N
            }
        } else {
            props.put(JAVA_PLATFORM_PROPERTY, getPlatformID(platform));
        }
        helper.putProperties(NbModuleProjectGenerator.PLATFORM_PROPERTIES_PATH, props);
    }
}