diff --git a/j2ee.clientproject/nbproject/project.xml b/j2ee.clientproject/nbproject/project.xml --- a/j2ee.clientproject/nbproject/project.xml +++ b/j2ee.clientproject/nbproject/project.xml @@ -161,6 +161,15 @@ made subject to such option by the copyr 4 1.29 + + + + org.netbeans.modules.java.api.common + + + + 0-1 + 1.0 diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/AppClientActionProvider.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/AppClientActionProvider.java --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/AppClientActionProvider.java +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/AppClientActionProvider.java @@ -77,6 +77,7 @@ import org.netbeans.modules.j2ee.deploym import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; import org.netbeans.modules.j2ee.deployment.plugins.api.ServerDebugInfo; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.spi.project.ActionProvider; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.EditableProperties; @@ -342,7 +343,7 @@ class AppClientActionProvider implements result=isSetMainClass(project.getSourceRoots().getRoots(), mainClass); } while (result != MainClassStatus.SET_AND_VALID); try { - if (updateHelper.requestSave()) { + if (updateHelper.requestUpdate()) { updateHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,ep); ProjectManager.getDefault().saveProject(project); } else { diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/AppClientFileBuiltQuery.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/AppClientFileBuiltQuery.java deleted file mode 100644 --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/AppClientFileBuiltQuery.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.j2ee.clientproject; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import org.openide.filesystems.FileObject; -import org.netbeans.api.queries.FileBuiltQuery; -import org.netbeans.spi.queries.FileBuiltQueryImplementation; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; - - - - - -public class AppClientFileBuiltQuery implements FileBuiltQueryImplementation, PropertyChangeListener { - - private FileBuiltQueryImplementation delegate; - private final AntProjectHelper helper; - private final PropertyEvaluator evaluator; - private final SourceRoots sourceRoots; - private final SourceRoots testRoots; - - AppClientFileBuiltQuery (AntProjectHelper helper, PropertyEvaluator evaluator, - SourceRoots sourceRoots, SourceRoots testRoots) { - assert helper != null && evaluator != null && sourceRoots != null && testRoots != null; - this.helper = helper; - this.evaluator = evaluator; - this.sourceRoots = sourceRoots; - this.testRoots = testRoots; - this.sourceRoots.addPropertyChangeListener (this); - this.testRoots.addPropertyChangeListener (this); - } - - public synchronized FileBuiltQuery.Status getStatus(FileObject file) { - if (this.delegate == null) { - this.delegate = createDelegate (); - } - return this.delegate.getStatus (file); - } - - - private FileBuiltQueryImplementation createDelegate () { - String[] srcRoots = this.sourceRoots.getRootProperties(); - String[] tstRoots = this.testRoots.getRootProperties(); - String[] from = new String [srcRoots.length + tstRoots.length]; - String[] to = new String [srcRoots.length + tstRoots.length]; - for (int i=0; i< srcRoots.length; i++) { - from[i] = "${" + srcRoots[i] + "}/*.java"; // NOI18N - to[i] = "${" + AppClientProjectProperties.BUILD_CLASSES_DIR + "}/*.class"; // NOI18N - } - for (int i=0; i() { - public Integer run() { - synchronized (AppClientSharabilityQuery.this) { - if (delegate == null) { - delegate = createDelegate (); - } - return new Integer(delegate.getSharability (file)); - } - } - }); - return ret.intValue(); - } - - public void propertyChange(PropertyChangeEvent evt) { - if (SourceRoots.PROP_ROOT_PROPERTIES.equals(evt.getPropertyName())) { - synchronized (this) { - this.delegate = null; - } - } - } - - private SharabilityQueryImplementation createDelegate () { - String[] srcProps = srcRoots.getRootProperties(); - String[] testProps = testRoots.getRootProperties(); - String[] props = new String [srcProps.length + testProps.length + 1]; - for (int i=0; i sourceRootProperties; - private List sourceRootNames; - private List sourceRoots; - private List sourceRootURLs; - private final PropertyChangeSupport support; - private final ProjectMetadataListener listener; - private final boolean isTest; - private final File projectDir; - - /** - * Creates new SourceRoots - * @param helper - * @param evaluator - * @param elementName the name of XML element under which are declared the roots - * @param newRootNameTemplate template for new property name of source root - */ - SourceRoots (UpdateHelper helper, PropertyEvaluator evaluator, ReferenceHelper refHelper, String elementName, boolean isTest, String newRootNameTemplate) { - assert helper != null && evaluator != null && refHelper != null && elementName != null && newRootNameTemplate != null; - this.helper = helper; - this.evaluator = evaluator; - this.refHelper = refHelper; - this.elementName = elementName; - this.isTest = isTest; - this.newRootNameTemplate = newRootNameTemplate; - this.projectDir = FileUtil.toFile(this.helper.getAntProjectHelper().getProjectDirectory()); - this.support = new PropertyChangeSupport(this); - this.listener = new ProjectMetadataListener(); - this.evaluator.addPropertyChangeListener (WeakListeners.propertyChange(this.listener,this.evaluator)); - this.helper.getAntProjectHelper().addAntProjectListener(WeakListeners.create(AntProjectListener.class, this.listener,this.helper)); - } - - - /** - * Returns the display names of soruce roots - * The returned array has the same length as an array returned by the getRootProperties. - * It may contain empty strings but not null. - * @return an array of String - */ - public String[] getRootNames() { - return ProjectManager.mutex().readAccess(new Mutex.Action() { - public String[] run() { - synchronized (SourceRoots.this) { - if (sourceRootNames == null) { - readProjectMetadata(); - } - } - return sourceRootNames.toArray(new String[sourceRootNames.size()]); - } - }); - } - - /** - * Returns names of Ant properties in the project.properties file holding the source roots. - * @return an array of String - */ - public String[] getRootProperties () { - return ProjectManager.mutex().readAccess(new Mutex.Action() { - public String[] run() { - synchronized (SourceRoots.this) { - if (sourceRootProperties == null) { - readProjectMetadata(); - } - } - return sourceRootProperties.toArray(new String[sourceRootProperties.size()]); - } - }); - } - - /** - * Returns the source roots - * @return an array of FileObject - */ - public FileObject[] getRoots () { - return ProjectManager.mutex().readAccess(new Mutex.Action() { - public FileObject[] run () { - synchronized (this) { - //Local caching - if (sourceRoots == null) { - String[] srcProps = getRootProperties(); - List result = new ArrayList(); - for (int i = 0; i() { - public URL[] run() { - synchronized (this) { - //Local caching - if (sourceRootURLs == null) { - String[] srcProps = getRootProperties(); - List result = new ArrayList(); - for (int i = 0; i oldRoots2props = new HashMap(); - for (int i=0; i newRoots2lab = new HashMap(); - for (int i=0; i0) { - Element root = (Element) rootsNodes.item(0); - ownerElement.removeChild(root); - } - //Remove all unused root properties - List newRoots = Arrays.asList(roots); - Map propsToRemove = new HashMap(oldRoots2props); - propsToRemove.keySet().removeAll(newRoots); - EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - for (Iterator it = propsToRemove.values().iterator(); it.hasNext();) { - String propName = it.next(); - props.remove(propName); - } - helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,props); - //Add the new roots - Document doc = ownerElement.getOwnerDocument(); - oldRoots2props.keySet().retainAll(newRoots); - for (Iterator it = newRoots.iterator(); it.hasNext();) { - URL newRoot = (URL) it.next (); - String rootName = oldRoots2props.get (newRoot); - if (rootName == null) { - //Root is new generate property for it - props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - String[] names = newRoot.getPath().split("/"); //NOI18N - rootName = MessageFormat.format(newRootNameTemplate,new Object[]{names[names.length-1],""}); //NOI18N - int rootIndex = 1; - while (props.containsKey(rootName)) { - rootIndex++; - rootName = MessageFormat.format(newRootNameTemplate,new Object[]{names[names.length-1],new Integer(rootIndex)}); - } - File f = FileUtil.normalizeFile(new File(URI.create(newRoot.toExternalForm()))); - File projDir = FileUtil.toFile(helper.getAntProjectHelper().getProjectDirectory()); - String path = f.getAbsolutePath(); - String prjPath = projDir.getAbsolutePath()+File.separatorChar; - if (path.startsWith(prjPath)) { - path = path.substring(prjPath.length()); - } - else { - path = refHelper.createForeignFileReference(f, JavaProjectConstants.SOURCES_TYPE_JAVA); - props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - } - props.put(rootName,path); - helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,props); - } - Element newRootNode = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "root"); //NOI18N - newRootNode.setAttribute("id",rootName); //NOI18N - String label = newRoots2lab.get (newRoot); - if (label != null && label.length()>0 && !label.equals (getRootDisplayName(null,rootName))) { //NOI18N - newRootNode.setAttribute("name",label); //NOI18N - } - ownerElement.appendChild (newRootNode); - } - helper.putPrimaryConfigurationData(cfgEl,true); - } - } - ); - } - - /** - * Translates root name into display name of source/test root - * @param rootName the name of root got from {@link SourceRoots#getRootNames} - * @param propName the name of property the root is stored in - * @return the label to be displayed - */ - public String getRootDisplayName (String rootName, String propName) { - if (rootName == null || rootName.length() ==0) { - //If the prop is src.dir use the default name - if (isTest && "test.src.dir".equals(propName)) { //NOI18N - rootName = DEFAULT_TEST_LABEL; - } - else if (!isTest && "src.dir".equals(propName)) { //NOI18N - rootName = DEFAULT_SOURCE_LABEL; - } - else { - //If the name is not given, it should be either a relative path in the project dir - //or absolute path when the root is not under the project dir - String propValue = evaluator.getProperty(propName); - File sourceRoot = propValue == null ? null : helper.getAntProjectHelper().resolveFile(propValue); - rootName = createInitialDisplayName(sourceRoot); - } - } - return rootName; - } - - /** - * Creates initial display name of source/test root - * @param sourceRoot the source root - * @return the label to be displayed - */ - public String createInitialDisplayName (File sourceRoot) { - String rootName; - if (sourceRoot != null) { - String srPath = sourceRoot.getAbsolutePath(); - String pdPath = projectDir.getAbsolutePath() + File.separatorChar; - if (srPath.startsWith(pdPath)) { - rootName = srPath.substring(pdPath.length()); - } - else { - rootName = sourceRoot.getAbsolutePath(); - } - } - else { - rootName = isTest ? DEFAULT_TEST_LABEL : DEFAULT_SOURCE_LABEL; - } - return rootName; - } - - /** - * Returns true if this SourceRoots instance represents source roots belonging to - * the tests compilation unit. - * @return boolean - */ - public boolean isTest () { - return this.isTest; - } - - private void resetCache (boolean isXMLChange, String propName) { - boolean fire = false; - synchronized (this) { - //In case of change reset local cache - if (isXMLChange) { - this.sourceRootProperties = null; - this.sourceRootNames = null; - this.sourceRoots = null; - this.sourceRootURLs = null; - fire = true; - } else if (propName == null || (sourceRootProperties != null && sourceRootProperties.contains(propName))) { - this.sourceRoots = null; - this.sourceRootURLs = null; - fire = true; - } - } - if (fire) { - if (isXMLChange) { - this.support.firePropertyChange (PROP_ROOT_PROPERTIES,null,null); - } - this.support.firePropertyChange (PROP_ROOTS,null,null); - } - } - - private void readProjectMetadata () { - Element cfgEl = helper.getPrimaryConfigurationData(true); - NodeList nl = cfgEl.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, elementName); - assert nl.getLength() == 0 || nl.getLength() == 1 : "Illegal project.xml"; //NOI18N - List rootProps = new ArrayList(); - List rootNames = new ArrayList(); - // It can be 0 in the case when the project is created by J2SEProjectGenerator and not yet customized - if (nl.getLength()==1) { - NodeList roots = ((Element)nl.item(0)).getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "root"); //NOI18N - for (int i=0; i 0 : "Illegal project.xml"; - rootProps.add(value); - value = root.getAttribute("name"); //NOI18N - rootNames.add (value); - } - } - this.sourceRootProperties = Collections.unmodifiableList(rootProps); - this.sourceRootNames = Collections.unmodifiableList(rootNames); - } - - private class ProjectMetadataListener implements PropertyChangeListener,AntProjectListener { - - public void propertyChange(PropertyChangeEvent evt) { - resetCache (false,evt.getPropertyName()); - } - - public void configurationXmlChanged(AntProjectEvent ev) { - resetCache (true,null); - } - - public void propertiesChanged(AntProjectEvent ev) { - //Handled by propertyChange - } - } - -} diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/UpdateHelper.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/UpdateHelper.java deleted file mode 100644 --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/UpdateHelper.java +++ /dev/null @@ -1,399 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.j2ee.clientproject; - -import java.io.IOException; -import javax.swing.JButton; -import org.netbeans.modules.j2ee.clientproject.api.AppClientProjectGenerator; -import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; -import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; -import org.w3c.dom.Comment; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.util.NbBundle; -import org.openide.util.Mutex; -import org.netbeans.api.project.Project; -import org.netbeans.api.project.ProjectManager; -import org.netbeans.spi.project.AuxiliaryConfiguration; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.EditableProperties; -import org.openide.util.Exceptions; - - -/** - * Proxy for the AntProjectHelper which defers the update of the project metadata - * to explicit user action. Currently it is hard coded for update from - * "http://www.netbeans.org/ns/j2se-project/1" to "http://www.netbeans.org/ns/j2se-project/2". - * In future it should define plugable SPI. - */ -public class UpdateHelper { - - private static final boolean TRANSPARENT_UPDATE = Boolean.getBoolean("carproject.transparentUpdate"); - private static final String BUILD_NUMBER = System.getProperty("netbeans.buildnumber"); // NOI18N - private static final String MINIMUM_ANT_VERSION_ELEMENT = "minimum-ant-version"; // NOI18N - - private final Project project; - private final AntProjectHelper helper; - private final AuxiliaryConfiguration cfg; - private final GeneratedFilesHelper genFileHelper; - private final Notifier notifier; - private boolean alreadyAskedInWriteAccess; - private Boolean isCurrent; - private Element cachedElement; - - /** - * Creates new UpdateHelper - * @param project - * @param helper AntProjectHelper - * @param cfg AuxiliaryConfiguration - * @param genFileHelper GeneratedFilesHelper - * @param notifier used to ask user about project update - */ - UpdateHelper (Project project, AntProjectHelper helper, AuxiliaryConfiguration cfg, GeneratedFilesHelper genFileHelper, Notifier notifier) { - assert project != null && helper != null && cfg != null && genFileHelper != null && notifier != null; - this.project = project; - this.helper = helper; - this.cfg = cfg; - this.genFileHelper = genFileHelper; - this.notifier = notifier; - } - - /** - * Returns the AntProjectHelper.getProperties(), {@link AntProjectHelper#getProperties(String)} - * @param path a relative URI in the project directory. - * @return a set of properties - */ - public EditableProperties getProperties (final String path) { - //Properties are the same in both j2seproject/1 and j2seproject/2 - return ProjectManager.mutex().readAccess(new Mutex.Action(){ - public EditableProperties run() { - if (!isCurrent() && AntProjectHelper.PROJECT_PROPERTIES_PATH.equals(path)) { //Only project properties were changed - return getUpdatedProjectProperties (); - } - else { - return helper.getProperties(path); - } - } - }); - } - - /** - * In the case that the project is of current version or the properties are not {@link AntProjectHelper#PROJECT_PROPERTIES_PATH} - * it calls AntProjectHelper.putProperties(), {@link AntProjectHelper#putProperties(String, EditableProperties)} - * otherwise it asks user to updata project. If the user agrees with the project update, it does the update and calls - * AntProjectHelper.putProperties(). - * @param path a relative URI in the project directory. - * @param props a set of properties - */ - public void putProperties(final String path, final EditableProperties props) { - ProjectManager.mutex().writeAccess(new Runnable() { - public void run() { - if (isCurrent() || !AntProjectHelper.PROJECT_PROPERTIES_PATH.equals(path)) { //Only project props should cause update - helper.putProperties(path,props); - } else if (canUpdate()) { - try { - saveUpdate(); - helper.putProperties(path,props); - } catch (IOException ioe) { - Exceptions.printStackTrace(ioe); - } - } - } - }); - } - - /** - * In the case that the project is of current version or shared is false it delegates to - * AntProjectHelper.getPrimaryConfigurationData(), {@link AntProjectHelper#getPrimaryConfigurationData(boolean)}. - * Otherwise it creates an in memory update of shared configuration data and returns it. - * @param shared if true, refers to project.xml, else refers to - * private.xml - * @return the configuration data that is available - */ - public Element getPrimaryConfigurationData (final boolean shared) { - return ProjectManager.mutex().readAccess(new Mutex.Action(){ - public Element run() { - if (!shared || isCurrent()) { //Only shared props should cause update - return helper.getPrimaryConfigurationData(shared); - } - return getUpdatedSharedConfigurationData (); - } - }); - } - - /** - * In the case that the project is of current version or shared is false it calls AntProjectHelper.putPrimaryConfigurationData(), - * {@link AntProjectHelper#putPrimaryConfigurationData(Element, boolean)}. - * Otherwise it asks user to update the project. If the user agrees with the project update, it does the update and calls - * AntProjectHelper.PrimaryConfigurationData(). - * @param element the configuration data - * @param shared if true, refers to project.xml, else refers to - * private.xml - */ - public void putPrimaryConfigurationData(final Element element, final boolean shared) { - ProjectManager.mutex().writeAccess(new Runnable() { - public void run() { - if (!shared || isCurrent()) { - helper.putPrimaryConfigurationData(element, shared); - } else if (canUpdate()) { - try { - saveUpdate(); - helper.putPrimaryConfigurationData(element, shared); - } catch (IOException ioe) { - Exceptions.printStackTrace(ioe); - } - } - } - }); - } - - /** - * Returns an AntProjectHelper. The helper may not be used for accessing/storing project metadata. - * For project metadata manipulation the UpdateHelper must be used. - * @return AntProjectHelper - */ - public AntProjectHelper getAntProjectHelper () { - return this.helper; - } - - /** - * Request an saving of update. If the project is not of current version the user will be asked to update the project. - * If the user agrees with an update the project is updated. - * @return true if the metadata are of current version or updated - */ - public boolean requestSave () throws IOException{ - if (isCurrent()) { - return true; - } - if (!canUpdate()) { - return false; - } - saveUpdate (); - return true; - } - - /** - * Returns true if the project is of current version. - * @return true if the project is of current version, otherwise false. - */ - public synchronized boolean isCurrent () { - /* - if (this.isCurrent == null) { - if ((this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/1",true) != null) || - (this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/2",true) != null)) { - this.isCurrent = Boolean.FALSE; - } else { - this.isCurrent = Boolean.TRUE; - } - } - return isCurrent.booleanValue(); - */ - //there are no other versions yet => we can always return true - return true; - } - - private boolean canUpdate () { - if (TRANSPARENT_UPDATE) { - return true; - } - //Ask just once under a single write access - if (alreadyAskedInWriteAccess) { - return false; - } - else { - boolean canUpdate = this.notifier.canUpdate(); - if (!canUpdate) { - alreadyAskedInWriteAccess = true; - ProjectManager.mutex().postReadRequest(new Runnable() { - public void run() { - alreadyAskedInWriteAccess = false; - } - }); - } - return canUpdate; - } - } - - private void saveUpdate () throws IOException { - this.helper.putPrimaryConfigurationData(getUpdatedSharedConfigurationData(),true); - this.cfg.removeConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/1",true); //NOI18N - this.cfg.removeConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/2",true); //NOI18N - ProjectManager.getDefault().saveProject (this.project); - synchronized(this) { - this.isCurrent = Boolean.TRUE; - } - } - - private synchronized Element getUpdatedSharedConfigurationData () { - if (cachedElement == null) { - Element oldRoot = this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/1",true); //NOI18N - if (oldRoot != null) { - Document doc = oldRoot.getOwnerDocument(); - Element newRoot = doc.createElementNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N - copyDocument (doc, oldRoot, newRoot); - Element sourceRoots = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N - Element root = doc.createElementNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N - root.setAttribute ("id","src.dir"); //NOI18N - sourceRoots.appendChild(root); - newRoot.appendChild (sourceRoots); - Element testRoots = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"test-roots"); //NOI18N - root = doc.createElementNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N - root.setAttribute ("id","test.src.dir"); //NOI18N - testRoots.appendChild (root); - newRoot.appendChild (testRoots); - cachedElement = updateMinAntVersion (newRoot, doc); - } else { - oldRoot = this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/2",true); //NOI18N - if (oldRoot != null) { - Document doc = oldRoot.getOwnerDocument(); - Element newRoot = doc.createElementNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N - copyDocument (doc, oldRoot, newRoot); - cachedElement = updateMinAntVersion (newRoot, doc); - } - } - } - return cachedElement; - } - - private synchronized EditableProperties getUpdatedProjectProperties () { - EditableProperties cachedProperties = this.helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - //The javadoc.additionalparam was not in NB 4.0 - if (cachedProperties.get (AppClientProjectProperties.JAVADOC_ADDITIONALPARAM)==null) { - cachedProperties.put (AppClientProjectProperties.JAVADOC_ADDITIONALPARAM,""); //NOI18N - } - if (cachedProperties.get ("build.generated.dir")==null) { //NOI18N - cachedProperties.put ("build.generated.dir","${build.dir}/generated"); //NOI18N - } - if (cachedProperties.get (AppClientProjectProperties.META_INF)==null) { //NOI18N - cachedProperties.put (AppClientProjectProperties.META_INF,"${src.dir}/conf"); //NOI18N - } - return cachedProperties; - } - - private static void copyDocument (Document doc, Element from, Element to) { - NodeList nl = from.getChildNodes(); - int length = nl.getLength(); - for (int i=0; i< length; i++) { - Node node = nl.item (i); - Node newNode = null; - switch (node.getNodeType()) { - case Node.ELEMENT_NODE: - Element oldElement = (Element) node; - newNode = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName()); - NamedNodeMap m = oldElement.getAttributes(); - Element newElement = (Element) newNode; - for (int index = 0; index < m.getLength(); index++) { - Node attr = m.item(index); - newElement.setAttribute(attr.getNodeName(), attr.getNodeValue()); - } - copyDocument(doc,oldElement,newElement); - break; - case Node.TEXT_NODE: - Text oldText = (Text) node; - newNode = doc.createTextNode(oldText.getData()); - break; - case Node.COMMENT_NODE: - Comment oldComment = (Comment) node; - newNode = doc.createComment(oldComment.getData()); - break; - } - if (newNode != null) { - to.appendChild (newNode); - } - } - } - - private static Element updateMinAntVersion (final Element root, final Document doc) { - NodeList list = root.getElementsByTagNameNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT); - if (list.getLength() == 1) { - Element me = (Element) list.item(0); - list = me.getChildNodes(); - if (list.getLength() == 1) { - me.replaceChild (doc.createTextNode(AppClientProjectGenerator.MINIMUM_ANT_VERSION), list.item(0)); - return root; - } - } - assert false : "Invalid project file"; //NOI18N - return root; - } - - /** - * Creates an default Notifier. The default notifier displays a dialog warning user about project update. - * @return notifier - */ - public static Notifier createDefaultNotifier () { - return new Notifier() { - public boolean canUpdate() { - JButton updateOption = new JButton (NbBundle.getMessage(UpdateHelper.class, "CTL_UpdateOption")); - updateOption.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(UpdateHelper.class, "AD_UpdateOption")); - return DialogDisplayer.getDefault().notify( - new NotifyDescriptor (NbBundle.getMessage(UpdateHelper.class,"TXT_ProjectUpdate", BUILD_NUMBER), - NbBundle.getMessage(UpdateHelper.class,"TXT_ProjectUpdateTitle"), - NotifyDescriptor.DEFAULT_OPTION, - NotifyDescriptor.WARNING_MESSAGE, - new Object[] { - updateOption, - NotifyDescriptor.CANCEL_OPTION - }, - updateOption)) == updateOption; - } - }; - } - - /** - * Interface used by the UpdateHelper to ask user about - * the project update. - */ - public static interface Notifier { - /** - * Asks user to update the project - * @return true if the project should be updated - */ - public boolean canUpdate (); - } -} diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/UpdateProjectImpl.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/UpdateProjectImpl.java new file mode 100644 --- /dev/null +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/UpdateProjectImpl.java @@ -0,0 +1,251 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.j2ee.clientproject; + +import java.io.IOException; +import javax.swing.JButton; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.modules.j2ee.clientproject.api.AppClientProjectGenerator; +import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; +import org.netbeans.modules.java.api.common.ant.UpdateImplementation; +import org.netbeans.spi.project.AuxiliaryConfiguration; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.EditableProperties; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.util.NbBundle; +import org.w3c.dom.Comment; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +/** + * + * @author Tomas Mysik + */ +public class UpdateProjectImpl implements UpdateImplementation { + + private static final boolean TRANSPARENT_UPDATE = Boolean.getBoolean("carproject.transparentUpdate"); + private static final String BUILD_NUMBER = System.getProperty("netbeans.buildnumber"); // NOI18N + private static final String MINIMUM_ANT_VERSION_ELEMENT = "minimum-ant-version"; // NOI18N + + private final Project project; + private final AntProjectHelper helper; + private final AuxiliaryConfiguration cfg; + private boolean alreadyAskedInWriteAccess; + private boolean isCurrent; + private Element cachedElement; + + /** + * Creates new UpdateHelper + * @param project + * @param helper AntProjectHelper + * @param cfg AuxiliaryConfiguration + * @param genFileHelper GeneratedFilesHelper + * @param notifier used to ask user about project update + */ + UpdateProjectImpl(Project project, AntProjectHelper helper, AuxiliaryConfiguration cfg) { + assert project != null && helper != null && cfg != null; + this.project = project; + this.helper = helper; + this.cfg = cfg; + } + + public boolean isCurrent() { + /* + if (this.isCurrent == null) { + if ((this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/1",true) != null) || + (this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/2",true) != null)) { + this.isCurrent = Boolean.FALSE; + } else { + this.isCurrent = Boolean.TRUE; + } + } + return isCurrent.booleanValue(); + */ + //there are no other versions yet => we can always return true + return true; + } + + public boolean canUpdate() { + if (TRANSPARENT_UPDATE) { + return true; + } + //Ask just once under a single write access + if (alreadyAskedInWriteAccess) { + return false; + } + else { + boolean canUpdate = showUpdateDialog(); + if (!canUpdate) { + alreadyAskedInWriteAccess = true; + ProjectManager.mutex().postReadRequest(new Runnable() { + public void run() { + alreadyAskedInWriteAccess = false; + } + }); + } + return canUpdate; + } + } + + public void saveUpdate(EditableProperties props) throws IOException { + this.helper.putPrimaryConfigurationData(getUpdatedSharedConfigurationData(),true); + this.cfg.removeConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/1",true); //NOI18N + this.cfg.removeConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/2",true); //NOI18N + ProjectManager.getDefault().saveProject (this.project); + synchronized(this) { + this.isCurrent = Boolean.TRUE; + } + } + + public Element getUpdatedSharedConfigurationData() { + if (cachedElement == null) { + Element oldRoot = this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/1",true); //NOI18N + if (oldRoot != null) { + Document doc = oldRoot.getOwnerDocument(); + Element newRoot = doc.createElementNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N + copyDocument (doc, oldRoot, newRoot); + Element sourceRoots = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N + Element root = doc.createElementNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N + root.setAttribute ("id","src.dir"); //NOI18N + sourceRoots.appendChild(root); + newRoot.appendChild (sourceRoots); + Element testRoots = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"test-roots"); //NOI18N + root = doc.createElementNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N + root.setAttribute ("id","test.src.dir"); //NOI18N + testRoots.appendChild (root); + newRoot.appendChild (testRoots); + cachedElement = updateMinAntVersion (newRoot, doc); + } else { + oldRoot = this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/2",true); //NOI18N + if (oldRoot != null) { + Document doc = oldRoot.getOwnerDocument(); + Element newRoot = doc.createElementNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N + copyDocument (doc, oldRoot, newRoot); + cachedElement = updateMinAntVersion (newRoot, doc); + } + } + } + return cachedElement; + } + + public EditableProperties getUpdatedProjectProperties() { + EditableProperties cachedProperties = this.helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + //The javadoc.additionalparam was not in NB 4.0 + if (cachedProperties.get (AppClientProjectProperties.JAVADOC_ADDITIONALPARAM)==null) { + cachedProperties.put (AppClientProjectProperties.JAVADOC_ADDITIONALPARAM,""); //NOI18N + } + if (cachedProperties.get ("build.generated.dir")==null) { //NOI18N + cachedProperties.put ("build.generated.dir","${build.dir}/generated"); //NOI18N + } + if (cachedProperties.get (AppClientProjectProperties.META_INF)==null) { //NOI18N + cachedProperties.put (AppClientProjectProperties.META_INF,"${src.dir}/conf"); //NOI18N + } + return cachedProperties; + } + + private static void copyDocument (Document doc, Element from, Element to) { + NodeList nl = from.getChildNodes(); + int length = nl.getLength(); + for (int i=0; i< length; i++) { + Node node = nl.item (i); + Node newNode = null; + switch (node.getNodeType()) { + case Node.ELEMENT_NODE: + Element oldElement = (Element) node; + newNode = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName()); + NamedNodeMap m = oldElement.getAttributes(); + Element newElement = (Element) newNode; + for (int index = 0; index < m.getLength(); index++) { + Node attr = m.item(index); + newElement.setAttribute(attr.getNodeName(), attr.getNodeValue()); + } + copyDocument(doc,oldElement,newElement); + break; + case Node.TEXT_NODE: + Text oldText = (Text) node; + newNode = doc.createTextNode(oldText.getData()); + break; + case Node.COMMENT_NODE: + Comment oldComment = (Comment) node; + newNode = doc.createComment(oldComment.getData()); + break; + } + if (newNode != null) { + to.appendChild (newNode); + } + } + } + + private static Element updateMinAntVersion (final Element root, final Document doc) { + NodeList list = root.getElementsByTagNameNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT); + if (list.getLength() == 1) { + Element me = (Element) list.item(0); + list = me.getChildNodes(); + if (list.getLength() == 1) { + me.replaceChild (doc.createTextNode(AppClientProjectGenerator.MINIMUM_ANT_VERSION), list.item(0)); + return root; + } + } + assert false : "Invalid project file"; //NOI18N + return root; + } + + private boolean showUpdateDialog() { + JButton updateOption = new JButton (NbBundle.getMessage(UpdateProjectImpl.class, "CTL_UpdateOption")); + updateOption.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(UpdateHelper.class, "AD_UpdateOption")); + return DialogDisplayer.getDefault().notify( + new NotifyDescriptor (NbBundle.getMessage(UpdateProjectImpl.class,"TXT_ProjectUpdate", BUILD_NUMBER), + NbBundle.getMessage(UpdateProjectImpl.class,"TXT_ProjectUpdateTitle"), + NotifyDescriptor.DEFAULT_OPTION, + NotifyDescriptor.WARNING_MESSAGE, + new Object[] { + updateOption, + NotifyDescriptor.CANCEL_OPTION + }, + updateOption)) == updateOption; + } +} diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/api/AppClientProjectGenerator.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/api/AppClientProjectGenerator.java --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/api/AppClientProjectGenerator.java +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/api/AppClientProjectGenerator.java @@ -58,10 +58,8 @@ import org.netbeans.modules.j2ee.clientp import org.netbeans.modules.j2ee.clientproject.AppClientProject; import org.netbeans.modules.j2ee.clientproject.AppClientProjectType; import org.netbeans.modules.j2ee.clientproject.AppClientProvider; -import org.netbeans.modules.j2ee.clientproject.UpdateHelper; import org.netbeans.modules.j2ee.clientproject.Utils; import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; -import org.netbeans.modules.j2ee.clientproject.ui.customizer.PlatformUiSupport; import org.netbeans.modules.j2ee.dd.api.client.AppClient; import org.netbeans.modules.j2ee.dd.api.client.DDProvider; import org.netbeans.modules.j2ee.deployment.devmodules.api.AntDeploymentHelper; @@ -69,6 +67,8 @@ import org.netbeans.modules.j2ee.deploym import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; +import org.netbeans.modules.java.api.common.ui.PlatformUiSupport; import org.netbeans.modules.websvc.api.client.WebServicesClientConstants; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.EditableProperties; @@ -637,7 +637,7 @@ public class AppClientProjectGenerator { if (sourceLevel.equals("1.6") || sourceLevel.equals("1.7")) { srcLevel = "1.5"; } - PlatformUiSupport.storePlatform(ep, updateHelper, finalPlatformName, srcLevel != null ? new SpecificationVersion(srcLevel) : null); + PlatformUiSupport.storePlatform(ep, updateHelper, AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, finalPlatformName, srcLevel != null ? new SpecificationVersion(srcLevel) : null); helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); ProjectManager.getDefault().saveProject(ProjectManager.getDefault().findProject(helper.getProjectDirectory())); } catch (IOException e) { diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/classpath/AppClientProjectClassPathExtender.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/classpath/AppClientProjectClassPathExtender.java --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/classpath/AppClientProjectClassPathExtender.java +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/classpath/AppClientProjectClassPathExtender.java @@ -62,8 +62,8 @@ import org.netbeans.spi.project.support. import org.netbeans.spi.project.support.ant.ReferenceHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.EditableProperties; -import org.netbeans.modules.j2ee.clientproject.UpdateHelper; import org.netbeans.modules.j2ee.clientproject.ui.customizer.AntArtifactChooser; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.openide.util.Exceptions; import org.openide.util.RequestProcessor; diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/classpath/ClassPathProviderImpl.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/classpath/ClassPathProviderImpl.java --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/classpath/ClassPathProviderImpl.java +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/classpath/ClassPathProviderImpl.java @@ -53,8 +53,8 @@ import org.netbeans.spi.java.project.cla import org.netbeans.spi.java.project.classpath.support.ProjectClassPathSupport; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.modules.j2ee.clientproject.SourceRoots; import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; +import org.netbeans.modules.java.api.common.SourceRoots; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.WeakListeners; diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/classpath/SourcePathImplementation.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/classpath/SourcePathImplementation.java --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/classpath/SourcePathImplementation.java +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/classpath/SourcePathImplementation.java @@ -49,10 +49,10 @@ import java.beans.PropertyChangeListener import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.net.URL; +import org.netbeans.modules.java.api.common.SourceRoots; import org.netbeans.spi.java.classpath.ClassPathImplementation; import org.netbeans.spi.java.classpath.PathResourceImplementation; import org.netbeans.spi.java.classpath.support.ClassPathSupport; -import org.netbeans.modules.j2ee.clientproject.SourceRoots; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.openide.util.Exceptions; diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/queries/AppClientProjectEncodingQueryImpl.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/queries/AppClientProjectEncodingQueryImpl.java deleted file mode 100644 --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/queries/AppClientProjectEncodingQueryImpl.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.j2ee.clientproject.queries; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.nio.charset.Charset; -import java.nio.charset.IllegalCharsetNameException; -import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; -import org.netbeans.spi.queries.FileEncodingQueryImplementation; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.openide.filesystems.FileObject; - -/** - * - * @author Tomas Zezula - */ -public class AppClientProjectEncodingQueryImpl extends FileEncodingQueryImplementation implements PropertyChangeListener { - - - private final PropertyEvaluator eval; - private Charset cache; - - /** Creates a new instance of J2SEProjectEncodingQueryImpl */ - public AppClientProjectEncodingQueryImpl(final PropertyEvaluator eval) { - assert eval != null; - this.eval = eval; - this.eval.addPropertyChangeListener(this); - } - - public Charset getEncoding(FileObject file) { - assert file != null; - synchronized (this) { - if (cache != null) { - return cache; - } - } - String enc = eval.getProperty(AppClientProjectProperties.SOURCE_ENCODING); - synchronized (this) { - if (cache == null) { - try { - cache = enc == null ? Charset.defaultCharset() : Charset.forName(enc); - } catch (IllegalCharsetNameException exception) { - return null; - } - } - return cache; - } - } - - public void propertyChange(PropertyChangeEvent event) { - String propName = event.getPropertyName(); - if (propName == null || propName.equals(AppClientProjectProperties.SOURCE_ENCODING)) { - synchronized (this) { - cache = null; - } - } - } - -} diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/queries/CompiledSourceForBinaryQuery.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/queries/CompiledSourceForBinaryQuery.java deleted file mode 100644 --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/queries/CompiledSourceForBinaryQuery.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.j2ee.clientproject.queries; - -import java.io.File; -import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; - -import java.net.URL; -import java.net.MalformedURLException; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeEvent; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.Map; -import java.util.HashMap; -import javax.swing.event.ChangeListener; -import javax.swing.event.ChangeEvent; - -import org.netbeans.api.java.queries.SourceForBinaryQuery; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.modules.j2ee.clientproject.SourceRoots; -import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; -import org.openide.util.Exceptions; - -/** - * Finds sources corresponding to binaries in a J2SE project. - * @author Jesse Glick, Tomas Zezula - */ -public class CompiledSourceForBinaryQuery implements SourceForBinaryQueryImplementation { - - private final AntProjectHelper helper; - private final PropertyEvaluator evaluator; - private final SourceRoots sourceRoots; - private final SourceRoots testRoots; - private Map cache = new HashMap(); - - public CompiledSourceForBinaryQuery(AntProjectHelper helper, PropertyEvaluator evaluator, SourceRoots srcRoots, SourceRoots testRoots) { - this.helper = helper; - this.evaluator = evaluator; - this.sourceRoots = srcRoots; - this.testRoots = testRoots; - } - - public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) { - if (FileUtil.getArchiveFile(binaryRoot) != null) { - binaryRoot = FileUtil.getArchiveFile(binaryRoot); - // XXX check whether this is really the root - } - SourceForBinaryQuery.Result res = cache.get(binaryRoot); - if (res != null) { - return res; - } - SourceRoots src = null; - if (hasSources(binaryRoot, AppClientProjectProperties.BUILD_CLASSES_DIR)) { - src = this.sourceRoots; - } else if (hasSources(binaryRoot, AppClientProjectProperties.DIST_JAR)) { - src = this.sourceRoots; - } else if (hasSources(binaryRoot, AppClientProjectProperties.BUILD_TEST_CLASSES_DIR)) { - src = this.testRoots; - } - if (src == null) { - return null; - } else { - res = new Result(src); - cache.put(binaryRoot, res); - return res; - } - } - - - private boolean hasSources(URL binaryRoot, String binaryProperty) { - try { - String outDir = evaluator.getProperty(binaryProperty); - if (outDir != null) { - File f = helper.resolveFile(outDir); - URL url = f.toURI().toURL(); - if (!f.exists() && !f.getPath().toLowerCase().endsWith(".jar")) { // NOI18N - // non-existing - assert !url.toExternalForm().endsWith("/") : f; // NOI18N - url = new URL(url.toExternalForm() + "/"); // NOI18N - } - if (url.equals(binaryRoot)) { - return true; - } - } - } catch (MalformedURLException malformedURL) { - Exceptions.printStackTrace(malformedURL); - } - return false; - } - - private static class Result implements SourceForBinaryQuery.Result, PropertyChangeListener { - - private ArrayList listeners; - private SourceRoots sourceRoots; - - public Result(SourceRoots sourceRoots) { - this.sourceRoots = sourceRoots; - this.sourceRoots.addPropertyChangeListener(this); - } - - public FileObject[] getRoots() { - return this.sourceRoots.getRoots(); //No need to cache it, SourceRoots does - } - - public synchronized void addChangeListener(ChangeListener l) { - if (this.listeners == null) { - this.listeners = new ArrayList(); - } - this.listeners.add(l); - } - - public synchronized void removeChangeListener(ChangeListener l) { - if (this.listeners == null) { - return; - } - this.listeners.remove(l); - } - - public void propertyChange(PropertyChangeEvent evt) { - if (SourceRoots.PROP_ROOTS.equals(evt.getPropertyName())) { - this.fireChange(); - } - } - - private void fireChange() { - Iterator it; - synchronized (this) { - if (this.listeners == null) { - return; - } - @SuppressWarnings("unchecked") - ArrayList cloned = (ArrayList) this.listeners.clone(); - it = cloned.iterator(); - } - ChangeEvent event = new ChangeEvent(this); - while (it.hasNext()) { - (it.next()).stateChanged(event); - } - } - - } - -} diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/queries/JavadocForBinaryQueryImpl.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/queries/JavadocForBinaryQueryImpl.java deleted file mode 100644 --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/queries/JavadocForBinaryQueryImpl.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.j2ee.clientproject.queries; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import javax.swing.event.ChangeEvent; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.openide.filesystems.FileUtil; -import java.net.URL; -import java.net.MalformedURLException; -import javax.swing.event.ChangeListener; -import org.netbeans.api.java.queries.JavadocForBinaryQuery; -import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; -import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.openide.util.Exceptions; -import org.openide.util.WeakListeners; - -/** - * Finds Javadoc (if it is built) corresponding to binaries in J2SE project. - * @author David Konecny, Jesse Glick - */ -public class JavadocForBinaryQueryImpl implements JavadocForBinaryQueryImplementation { - - private static final String PROP_JAVADOC_DIR = "dist.javadoc.dir"; //NOI18N - - private final AntProjectHelper helper; - private final PropertyEvaluator evaluator; - - public JavadocForBinaryQueryImpl(AntProjectHelper helper, PropertyEvaluator evaluator) { - this.helper = helper; - this.evaluator = evaluator; - } - - public JavadocForBinaryQuery.Result findJavadoc(final URL binaryRoot) { - - class R implements JavadocForBinaryQuery.Result, PropertyChangeListener { - - private List listeners; - private URL[] result; - - public R () { - JavadocForBinaryQueryImpl.this.evaluator.addPropertyChangeListener (WeakListeners.propertyChange(this,JavadocForBinaryQueryImpl.this.evaluator)); - } - - public synchronized URL[] getRoots() { - if (this.result == null) { - String javadocDir = evaluator.getProperty(AppClientProjectProperties.DIST_JAVADOC_DIR); - if (javadocDir != null) { - File f = helper.resolveFile(javadocDir); - try { - URL url = f.toURI().toURL(); - if (!f.exists()) { - assert !url.toExternalForm().endsWith("/") : f; // NOI18N - url = new URL(url.toExternalForm() + "/"); // NOI18N - } - this.result = new URL[] {url}; - } catch (MalformedURLException e) { - this.result = new URL[0]; - Exceptions.printStackTrace(e); - } - } - else { - this.result = new URL[0]; - } - } - return this.result; - } - public synchronized void addChangeListener(final ChangeListener l) { - assert l != null; - if (this.listeners == null) { - this.listeners = new ArrayList(); - } - this.listeners.add (l); - } - public synchronized void removeChangeListener(final ChangeListener l) { - assert l != null; - if (this.listeners == null) { - return; - } - this.listeners.remove (l); - } - - public void propertyChange (final PropertyChangeEvent event) { - if (AppClientProjectProperties.DIST_JAVADOC_DIR.equals(event.getPropertyName())) { - synchronized (this) { - result = null; - } - this.fireChange (); - } - } - - private void fireChange () { - ChangeListener[] _listeners; - synchronized (this) { - if (this.listeners == null) { - return; - } - _listeners = this.listeners.toArray (new ChangeListener[this.listeners.size()]); - } - ChangeEvent event = new ChangeEvent (this); - for (int i=0; i<_listeners.length; i++) { - _listeners[i].stateChanged(event); - } - } - } - if (isRootOwner(binaryRoot, AppClientProjectProperties.BUILD_CLASSES_DIR) || isRootOwner (binaryRoot, AppClientProjectProperties.DIST_JAR)) { //NOI18N - return new R(); - } - return null; - } - - private boolean isRootOwner (URL binaryRoot, String binaryProperty) { - try { - if (FileUtil.getArchiveFile(binaryRoot) != null) { - binaryRoot = FileUtil.getArchiveFile(binaryRoot); - // XXX check whether this is really the root - } - String outDir = evaluator.getProperty(binaryProperty); - if (outDir != null) { - File f = helper.resolveFile (outDir); - URL url = f.toURI().toURL(); - if (!f.exists() && !f.getPath().toLowerCase().endsWith(".jar")) { // NOI18N - assert !url.toExternalForm().endsWith("/") : f; // NOI18N - url = new URL(url.toExternalForm() + "/"); // NOI18N - } - return url.equals(binaryRoot) || - binaryRoot.toExternalForm().startsWith(url.toExternalForm()); - } - } catch (MalformedURLException malformedURL) { - Exceptions.printStackTrace(malformedURL); - } - return false; - } - -// private URL getJavadoc(URL binaryRoot, String binaryProperty, String javadocProperty) { -// try { -// if (FileUtil.getArchiveFile(binaryRoot) != null) { -// binaryRoot = FileUtil.getArchiveFile(binaryRoot); -// } -// String outDir = evaluator.getProperty(binaryProperty); -// if (outDir != null) { -// File f = helper.resolveFile (outDir); -// URL url = f.toURI().toURL(); -// if (!f.exists() && !f.getPath().toLowerCase().endsWith(".jar")) { -// assert !url.toExternalForm().endsWith("/") : f; -// url = new URL(url.toExternalForm() + "/"); -// } -// if (url.equals(binaryRoot) || -// binaryRoot.toExternalForm().startsWith(url.toExternalForm())) { -// String javadocDir = evaluator.getProperty(javadocProperty); -// if (javadocDir != null) { -// f = helper.resolveFile(javadocDir); -// return f.toURI().toURL(); -// } -// } -// } -// } catch (MalformedURLException malformedURL) { -// ErrorManager.getDefault().notify(malformedURL); -// } -// return null; -// } - -} diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/queries/SourceLevelQueryImpl.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/queries/SourceLevelQueryImpl.java deleted file mode 100644 --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/queries/SourceLevelQueryImpl.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.j2ee.clientproject.queries; - -import org.netbeans.modules.j2ee.clientproject.AppClientProjectUtil; -import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; -import org.netbeans.spi.java.queries.SourceLevelQueryImplementation; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.spi.project.support.ant.PropertyUtils; -import org.netbeans.spi.project.support.ant.EditableProperties; -import org.openide.filesystems.FileObject; - -/** - * Returns source level of project sources. - * @author David Konecny - */ -public class SourceLevelQueryImpl implements SourceLevelQueryImplementation { - - private final PropertyEvaluator evaluator; - - public SourceLevelQueryImpl(PropertyEvaluator evaluator) { - this.evaluator = evaluator; - } - - public String getSourceLevel(FileObject javaFile) { - final String activePlatform = evaluator.getProperty (AppClientProjectProperties.JAVA_PLATFORM); //NOI18N - if (AppClientProjectUtil.getActivePlatform(activePlatform) != null) { - String sl = evaluator.getProperty("javac.source"); //NOI18N - if (sl != null && sl.length() > 0) { - return sl; - } else { - return null; - } - } - else { - EditableProperties props = PropertyUtils.getGlobalProperties(); - String sl = props.get("default.javac.source"); //NOI18N - if (sl != null && sl.length() > 0) { - return sl; - } else { - return null; - } - } - } - -} diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/queries/UnitTestForSourceQueryImpl.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/queries/UnitTestForSourceQueryImpl.java deleted file mode 100644 --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/queries/UnitTestForSourceQueryImpl.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.j2ee.clientproject.queries; - -import java.net.URL; -import org.netbeans.api.project.FileOwnerQuery; -import org.netbeans.api.project.Project; -import org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation; -import org.netbeans.modules.j2ee.clientproject.SourceRoots; -import org.openide.filesystems.FileObject; - -public class UnitTestForSourceQueryImpl implements MultipleRootsUnitTestForSourceQueryImplementation { - - private final SourceRoots sourceRoots; - private final SourceRoots testRoots; - - public UnitTestForSourceQueryImpl(SourceRoots sourceRoots, SourceRoots testRoots) { - this.sourceRoots = sourceRoots; - this.testRoots = testRoots; - } - - public URL[] findUnitTests(FileObject source) { - return find(source, sourceRoots, testRoots); // NOI18N - } - - public URL[] findSources(FileObject unitTest) { - return find(unitTest, testRoots, sourceRoots); // NOI18N - } - - private URL[] find(FileObject file, SourceRoots from, SourceRoots to) { - Project p = FileOwnerQuery.getOwner(file); - if (p == null) { - return null; - } - FileObject[] fromRoots = from.getRoots(); - for (int i = 0; i < fromRoots.length; i++) { - if (fromRoots[i].equals(file)) { - return to.getRootURLs(); - } - } - return null; - } - -} diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/ActionFilterNode.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/ActionFilterNode.java --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/ActionFilterNode.java +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/ActionFilterNode.java @@ -65,8 +65,8 @@ import org.netbeans.api.java.queries.Jav import org.netbeans.api.java.queries.JavadocForBinaryQuery; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.EditableProperties; -import org.netbeans.modules.j2ee.clientproject.UpdateHelper; import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.ReferenceHelper; import org.openide.nodes.FilterNode.Children; diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/AppClientLogicalViewProvider.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/AppClientLogicalViewProvider.java --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/AppClientLogicalViewProvider.java +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/AppClientLogicalViewProvider.java @@ -81,8 +81,6 @@ import org.netbeans.modules.j2ee.api.ejb import org.netbeans.modules.j2ee.api.ejbjar.EjbProjectConstants; import org.netbeans.modules.j2ee.clientproject.AppClientProject; import org.netbeans.modules.j2ee.clientproject.AppClientProjectUtil; -import org.netbeans.modules.j2ee.clientproject.SourceRoots; -import org.netbeans.modules.j2ee.clientproject.UpdateHelper; import org.netbeans.modules.j2ee.clientproject.classpath.ClassPathSupport; import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; import org.netbeans.modules.j2ee.clientproject.ui.customizer.CustomizerLibraries; @@ -95,6 +93,8 @@ import org.netbeans.modules.j2ee.deploym import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; import org.netbeans.modules.j2ee.spi.ejbjar.support.J2eeProjectView; +import org.netbeans.modules.java.api.common.SourceRoots; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.modules.websvc.api.client.WebServicesClientSupport; import org.netbeans.modules.websvc.api.client.WebServicesClientView; import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientSupport; @@ -632,7 +632,7 @@ public class AppClientLogicalViewProvide public void actionPerformed(ActionEvent e) { try { - helper.requestSave(); + helper.requestUpdate(); BrokenReferencesSupport.showCustomizer(helper.getAntProjectHelper(), resolver, getBreakableProperties(), new String[] {AppClientProjectProperties.JAVA_PLATFORM}); run(); } catch (IOException ioe) { diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/LibrariesNode.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/LibrariesNode.java --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/LibrariesNode.java +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/LibrariesNode.java @@ -102,11 +102,11 @@ import org.netbeans.spi.project.support. import org.netbeans.spi.project.support.ant.ReferenceHelper; import org.netbeans.spi.java.project.support.ui.PackageView; import org.netbeans.spi.java.classpath.support.ClassPathSupport; -import org.netbeans.modules.j2ee.clientproject.UpdateHelper; import org.netbeans.modules.j2ee.clientproject.classpath.AppClientProjectClassPathExtender; import org.netbeans.modules.j2ee.clientproject.ui.customizer.AntArtifactChooser; import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientClassPathUi; import org.netbeans.modules.j2ee.clientproject.ui.customizer.LibrariesChooser; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.openide.util.Exceptions; diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/ProjectNode.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/ProjectNode.java --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/ProjectNode.java +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/ProjectNode.java @@ -81,8 +81,8 @@ import org.netbeans.spi.project.support. import org.netbeans.spi.project.support.ant.EditableProperties; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.ReferenceHelper; -import org.netbeans.modules.j2ee.clientproject.UpdateHelper; import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.openide.filesystems.FileObject; import org.openide.util.Exceptions; diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/AppClientProjectProperties.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/AppClientProjectProperties.java --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/AppClientProjectProperties.java +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/AppClientProjectProperties.java @@ -71,9 +71,8 @@ import org.netbeans.api.queries.Collocat import org.netbeans.api.queries.CollocationQuery; import org.netbeans.api.queries.FileEncodingQuery; import org.netbeans.modules.j2ee.clientproject.AppClientProject; +import org.netbeans.modules.j2ee.clientproject.AppClientProjectType; import org.netbeans.modules.j2ee.clientproject.AppClientProjectUtil; -import org.netbeans.modules.j2ee.clientproject.SourceRoots; -import org.netbeans.modules.j2ee.clientproject.UpdateHelper; import org.netbeans.modules.j2ee.clientproject.Utils; import org.netbeans.modules.j2ee.clientproject.classpath.ClassPathSupport; import org.netbeans.modules.j2ee.deployment.devmodules.api.AntDeploymentHelper; @@ -81,6 +80,9 @@ import org.netbeans.modules.j2ee.deploym import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; +import org.netbeans.modules.java.api.common.SourceRoots; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; +import org.netbeans.modules.java.api.common.ui.PlatformUiSupport; import org.netbeans.modules.websvc.api.client.WebServicesClientConstants; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.EditableProperties; @@ -94,7 +96,6 @@ import org.openide.filesystems.FileObjec import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; -import org.openide.modules.SpecificationVersion; import org.openide.util.Exceptions; import org.openide.util.Mutex; import org.openide.util.MutexException; @@ -339,7 +340,11 @@ public class AppClientProjectProperties RUN_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator(projectProperties.get( RUN_TEST_CLASSPATH ), null ) ); PLATFORM_MODEL = PlatformUiSupport.createPlatformComboBoxModel (evaluator.getProperty(JAVA_PLATFORM)); PLATFORM_LIST_RENDERER = PlatformUiSupport.createPlatformListCellRenderer(); - JAVAC_SOURCE_MODEL = PlatformUiSupport.createSourceLevelComboBoxModel (PLATFORM_MODEL, evaluator.getProperty(JAVAC_SOURCE), evaluator.getProperty(JAVAC_TARGET), evaluator.getProperty(J2EE_PLATFORM)); + PlatformUiSupport.JDK minimalSourceLevel = null; + if (evaluator.getProperty(J2EE_PLATFORM).equals(JAVA_EE_5)) { + minimalSourceLevel = PlatformUiSupport.JDK.VERSION_5; + } + JAVAC_SOURCE_MODEL = PlatformUiSupport.createSourceLevelComboBoxModel(PLATFORM_MODEL, evaluator.getProperty(JAVAC_SOURCE), evaluator.getProperty(JAVAC_TARGET), minimalSourceLevel); JAVAC_SOURCE_RENDERER = PlatformUiSupport.createSourceLevelListCellRenderer (); // CustomizerCompile @@ -472,7 +477,7 @@ public class AppClientProjectProperties projectProperties.setProperty( RUN_TEST_CLASSPATH, run_test_cp ); //Handle platform selection and javac.source javac.target properties - PlatformUiSupport.storePlatform (projectProperties, updateHelper,PLATFORM_MODEL.getSelectedItem(), JAVAC_SOURCE_MODEL.getSelectedItem()); + PlatformUiSupport.storePlatform (projectProperties, updateHelper, AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, PLATFORM_MODEL.getSelectedItem(), JAVAC_SOURCE_MODEL.getSelectedItem()); // Handle other special cases if ( NO_DEPENDENCIES_MODEL.isSelected() ) { // NOI18N diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/AppClientSourceRootsUi.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/AppClientSourceRootsUi.java --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/AppClientSourceRootsUi.java +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/AppClientSourceRootsUi.java @@ -83,7 +83,7 @@ import org.netbeans.api.project.FileOwne import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectInformation; -import org.netbeans.modules.j2ee.clientproject.SourceRoots; +import org.netbeans.modules.java.api.common.SourceRoots; import org.openide.DialogDisplayer; import org.openide.DialogDescriptor; import org.openide.filesystems.FileObject; diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/CustomizerLibraries.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/CustomizerLibraries.java --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/CustomizerLibraries.java +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/CustomizerLibraries.java @@ -55,6 +55,7 @@ import org.netbeans.api.java.platform.Pl import org.netbeans.api.java.platform.PlatformsCustomizer; import org.netbeans.modules.j2ee.clientproject.classpath.ClassPathSupport; import org.netbeans.modules.j2ee.clientproject.ui.AppClientLogicalViewProvider; +import org.netbeans.modules.java.api.common.ui.PlatformUiSupport; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/CustomizerProviderImpl.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/CustomizerProviderImpl.java --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/CustomizerProviderImpl.java +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/CustomizerProviderImpl.java @@ -50,10 +50,9 @@ import java.util.HashMap; import java.util.HashMap; import java.util.Map; import org.netbeans.api.project.Project; -import org.netbeans.api.project.ProjectManager; import org.netbeans.api.project.ProjectUtils; import org.netbeans.modules.j2ee.clientproject.AppClientProject; -import org.netbeans.modules.j2ee.clientproject.UpdateHelper; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.ReferenceHelper; diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/CustomizerRun.form b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/CustomizerRun.form --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/CustomizerRun.form +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/CustomizerRun.form @@ -1,8 +1,9 @@ -
+ + diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/CustomizerRun.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/CustomizerRun.java --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/CustomizerRun.java +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/CustomizerRun.java @@ -53,7 +53,7 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.netbeans.modules.j2ee.clientproject.AppClientProject; -import org.netbeans.modules.j2ee.clientproject.SourceRoots; +import org.netbeans.modules.java.api.common.SourceRoots; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import org.openide.awt.MouseUtils; diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/PlatformUiSupport.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/PlatformUiSupport.java deleted file mode 100644 --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/ui/customizer/PlatformUiSupport.java +++ /dev/null @@ -1,705 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.j2ee.clientproject.ui.customizer; - -import java.awt.Component; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.AbstractListModel; -import javax.swing.ComboBoxModel; -import javax.swing.JButton; -import javax.swing.JList; -import javax.swing.ListCellRenderer; -import javax.swing.event.ListDataEvent; -import javax.swing.event.ListDataListener; -import org.netbeans.api.java.platform.JavaPlatform; -import org.netbeans.api.java.platform.JavaPlatformManager; -import org.netbeans.api.java.platform.Specification; -import org.netbeans.modules.j2ee.clientproject.AppClientProjectType; -import org.netbeans.modules.j2ee.clientproject.UpdateHelper; -import org.netbeans.spi.project.support.ant.EditableProperties; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.awt.HtmlRenderer; -import org.openide.modules.SpecificationVersion; -import org.openide.util.NbBundle; -import org.openide.util.WeakListeners; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -/** - * Support class for {@link JavaPlatform} manipulation in j2seproject customizer. - * @author tzezula - */ -public class PlatformUiSupport { - - private static final SpecificationVersion JDK_5 = new SpecificationVersion ("1.5"); //NOI18N - private static final SpecificationVersion JDK_6 = new SpecificationVersion ("1.6"); //NOI18N - private static final Logger LOGGER = Logger.getLogger(PlatformUiSupport.class.getName()); - - private PlatformUiSupport() { - } - - /** - * Creates {@link ComboBoxModel} of J2SE platforms. - * The model listens on the {@link JavaPlatformManager} and update its - * state according to changes - * @param activePlatform the active project's platform - * @return {@link ComboBoxModel} - */ - public static ComboBoxModel createPlatformComboBoxModel(String activePlatform) { - return new PlatformComboBoxModel(activePlatform); - } - - - /** - * Creates a {@link ListCellRenderer} for rendering items of the {@link ComboBoxModel} - * created by the {@link PlatformUiSupport#createPlatformComboBoxModel} method. - * @return {@link ListCellRenderer} - */ - public static ListCellRenderer createPlatformListCellRenderer() { - return new PlatformListCellRenderer(); - } - - /** - * Like {@link #storePlatform}, but platformName may be null (in which case the default platform is used) - */ - public static void storePlatform(EditableProperties props, UpdateHelper helper, String platformName, SpecificationVersion sourceLevel) { - PlatformKey platformKey; - if (platformName != null) { - platformKey = new PlatformKey(PlatformUiSupport.findPlatform(platformName)); - } else { - platformKey = new PlatformKey(JavaPlatformManager.getDefault().getDefaultPlatform()); - } - storePlatform(props, helper, platformKey, new SourceLevelKey(sourceLevel)); - } - - public static JavaPlatform findPlatform(String displayName) { - JavaPlatform[] platforms = JavaPlatformManager.getDefault().getPlatforms(displayName, new Specification("j2se", null)); //NOI18N - return platforms.length == 0 ? null : platforms[0]; - } - - /** - * Stores active platform, javac.source and javac.target into the project's metadata - * @param props project's shared properties - * @param helper to read/update project.xml - * @param platformKey the PatformKey got from the platform model - * @param sourceLevel source level - */ - public static void storePlatform(EditableProperties props, UpdateHelper helper, Object platformKey, Object sourceLevelKey) { - assert platformKey instanceof PlatformKey; - PlatformKey pk = (PlatformKey) platformKey; - JavaPlatform platform = getPlatform(pk); - //null means active broken (unresolved) platform, no need to do anything - if (platform != null) { - SpecificationVersion jdk13 = new SpecificationVersion("1.3"); //NOI18N - String platformAntName = platform.getProperties().get("platform.ant.name"); //NOI18N - assert platformAntName != null; - props.put(AppClientProjectProperties.JAVA_PLATFORM, platformAntName); - Element root = helper.getPrimaryConfigurationData(true); - boolean defaultPlatform = pk.isDefaultPlatform(); - boolean changed = false; - NodeList explicitPlatformNodes = root.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"explicit-platform"); //NOI18N - if (defaultPlatform) { - if (explicitPlatformNodes.getLength()==1) { - root.removeChild(explicitPlatformNodes.item(0)); - changed = true; - } - } else { - Element explicitPlatform; - switch (explicitPlatformNodes.getLength()) { - case 0: - explicitPlatform = root.getOwnerDocument().createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "explicit-platform"); //NOI18N - NodeList sourceRootNodes = root.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N - assert sourceRootNodes.getLength() == 1 : "Broken project.xml file"; //NOI18N - root.insertBefore(explicitPlatform, sourceRootNodes.item(0)); - changed = true; - break; - case 1: - explicitPlatform = (Element)explicitPlatformNodes.item(0); - break; - default: - throw new AssertionError("Broken project.xml file"); //NOI18N - } - String explicitSourceAttrValue = explicitPlatform.getAttribute("explicit-source-supported"); //NOI18N - if (jdk13.compareTo(platform.getSpecification().getVersion())>=0 && - !"false".equals(explicitSourceAttrValue)) { //NOI18N - explicitPlatform.setAttribute("explicit-source-supported","false"); //NOI18N - changed = true; - } else if (jdk13.compareTo(platform.getSpecification().getVersion())<0 && - !"true".equals(explicitSourceAttrValue)) { //NOI18N - explicitPlatform.setAttribute("explicit-source-supported","true"); //NOI18N - changed = true; - } - } - - SpecificationVersion sourceLevel; - if (sourceLevelKey == null) { - sourceLevel = platform.getSpecification().getVersion(); - } - else { - assert sourceLevelKey instanceof SourceLevelKey; - sourceLevel = ((SourceLevelKey)sourceLevelKey).getSourceLevel(); - } - String javacSource = sourceLevel.toString(); - String javacTarget = javacSource; - - //Issue #116490 - // Customizer value | -source | -target - // JDK 1.2 1.2 1.1 - // JDK 1.3 1.3 1.1 - // JDK 1.4 1.4 1.4 - // JDK 5 1.5 1.5 - // JDK 6 1.5 1.6 - // JDK 7 1.7 1.7 - should bring a new language features - if (jdk13.compareTo(sourceLevel)>=0) { - javacTarget = "1.1"; //NOI18N - } - else if (JDK_6.equals(sourceLevel)) { - javacSource = JDK_5.toString(); //NOI18N - } - - // #89131: these levels are not actually distinct from 1.5. - if (javacSource.equals("1.6") || javacSource.equals("1.7")) { - javacSource = "1.5"; - } - if (!javacSource.equals(props.getProperty(AppClientProjectProperties.JAVAC_SOURCE))) { - props.setProperty(AppClientProjectProperties.JAVAC_SOURCE, javacSource); - } - if (!javacTarget.equals(props.getProperty(AppClientProjectProperties.JAVAC_TARGET))) { - props.setProperty(AppClientProjectProperties.JAVAC_TARGET, javacTarget); - } - - if (changed) { - helper.putPrimaryConfigurationData(root, true); - } - } - } - - - /** - * Returns a {@link JavaPlatform} for an item obtained from the ComboBoxModel created by - * the {@link PlatformUiSupport#createComboBoxModel} method - * @param platformKey an item obtained from ComboBoxModel created by {@link PlatformUiSupport#createComboBoxModel} - * @return JavaPlatform or null in case when platform is broken - * @exception {@link IllegalArgumentException} is thrown in case when parameter in not an object created by - * platform combobox model. - */ - public static JavaPlatform getPlatform(Object platformKey) { - if (platformKey instanceof PlatformKey) { - return getPlatform((PlatformKey)platformKey); - } else { - throw new IllegalArgumentException(); - } - } - - /** - * Creates {@link ComboBoxModel} of source levels for active platform. - * The model listens on the platform's {@link ComboBoxModel} and update its - * state according to changes - * @param platformComboBoxModel the platform's model used for listenning - * @param initialSourceLevel initial source level value - * @param initialTargetLevel initial target level value - * @return {@link ComboBoxModel} of {@link SpecificationVersion} - */ - public static ComboBoxModel createSourceLevelComboBoxModel(ComboBoxModel platformComboBoxModel, String initialSourceLevel, String initialTargetLevel, String j2eePlatform) { - return new SourceLevelComboBoxModel(platformComboBoxModel, initialSourceLevel, initialTargetLevel, j2eePlatform); - } - - public static ListCellRenderer createSourceLevelListCellRenderer() { - return new SourceLevelListCellRenderer(); - } - - - private static JavaPlatform getPlatform(PlatformKey platformKey) { - return platformKey.platform; - } - - - /** - * This class represents a JavaPlatform in the {@link ListModel} - * created by the {@link PlatformUiSupport#createPlatformComboBoxModel} - * method. - */ - private static class PlatformKey implements Comparable { - - private String name; - private JavaPlatform platform; - - /** - * Creates a PlatformKey for a broken platform - * @param name the ant name of the broken platform - */ - public PlatformKey(String name) { - assert name != null; - this.name = name; - } - - /** - * Creates a PlatformKey for a platform - * @param platform the {@link JavaPlatform} - */ - public PlatformKey(JavaPlatform platform) { - assert platform != null; - this.platform = platform; - } - - public int compareTo(Object o) { - return this.getDisplayName().compareTo(((PlatformKey)o).getDisplayName()); - } - - @Override - public boolean equals(Object other) { - if (other instanceof PlatformKey) { - PlatformKey otherKey = (PlatformKey)other; - return (this.platform == null ? otherKey.platform == null : this.platform.equals(otherKey.platform)) && - otherKey.getDisplayName().equals(this.getDisplayName()); - } else { - return false; - } - } - - @Override - public int hashCode() { - return getDisplayName().hashCode(); - } - - @Override - public String toString() { - return getDisplayName(); - } - - public synchronized String getDisplayName() { - if (this.name == null) { - this.name = this.platform.getDisplayName(); - } - return this.name; - } - - public boolean isDefaultPlatform() { - if (this.platform == null) { - return false; - } - return this.platform.equals(JavaPlatformManager.getDefault().getDefaultPlatform()); - } - - public boolean isBroken() { - return this.platform == null; - } - - } - - private static final class SourceLevelKey implements Comparable { - - final SpecificationVersion sourceLevel; - final boolean broken; - - public SourceLevelKey(final SpecificationVersion sourceLevel) { - this(sourceLevel, false); - } - - public SourceLevelKey(final SpecificationVersion sourceLevel, final boolean broken) { - assert sourceLevel != null : "Source level cannot be null"; //NOI18N - this.sourceLevel = sourceLevel; - this.broken = broken; - } - - public SpecificationVersion getSourceLevel() { - return this.sourceLevel; - } - - public boolean isBroken() { - return this.broken; - } - - public int compareTo(final Object other) { - assert other instanceof SourceLevelKey : "Illegal argument of SourceLevelKey.compareTo()"; //NOI18N - SourceLevelKey otherKey = (SourceLevelKey) other; - return this.sourceLevel.compareTo(otherKey.sourceLevel); - } - - @Override - public boolean equals(final Object other) { - return (other instanceof SourceLevelKey) && - ((SourceLevelKey)other).sourceLevel.equals(this.sourceLevel); - } - - @Override - public int hashCode() { - return this.sourceLevel.hashCode(); - } - - @Override - public String toString() { - StringBuffer buffer = new StringBuffer(); - if (this.broken) { - buffer.append("Broken: "); //NOI18N - } - buffer.append(this.sourceLevel.toString()); - return buffer.toString(); - } - - public String getDisplayName () { - String _tmp = sourceLevel.toString(); - if (JDK_5.compareTo(sourceLevel)<=0) { - _tmp = _tmp.replaceFirst("^1\\.([5-9]|\\d\\d+)$", "$1"); //NOI18N - } - return NbBundle.getMessage(PlatformUiSupport.class, "LBL_JDK",_tmp); - } - - } - - private static class PlatformComboBoxModel extends AbstractListModel implements ComboBoxModel, PropertyChangeListener { - private static final long serialVersionUID = 1L; - - private final JavaPlatformManager pm; - private PlatformKey[] platformNamesCache; - private String initialPlatform; - private PlatformKey selectedPlatform; - - public PlatformComboBoxModel(String initialPlatform) { - this.pm = JavaPlatformManager.getDefault(); - this.pm.addPropertyChangeListener(WeakListeners.propertyChange(this, this.pm)); - this.initialPlatform = initialPlatform; - } - - public int getSize() { - PlatformKey[] platformNames = getPlatformNames(); - return platformNames.length; - } - - public Object getElementAt(int index) { - PlatformKey[] platformNames = getPlatformNames(); - assert index >=0 && index< platformNames.length; - return platformNames[index]; - } - - public Object getSelectedItem() { - this.getPlatformNames(); //Force setting of selectedPlatform if it is not alredy done - return this.selectedPlatform; - } - - public void setSelectedItem(Object obj) { - this.selectedPlatform = (PlatformKey) obj; - this.fireContentsChanged(this, -1, -1); - } - - public void propertyChange(PropertyChangeEvent event) { - if (JavaPlatformManager.PROP_INSTALLED_PLATFORMS.equals(event.getPropertyName())) { - synchronized (this) { - this.platformNamesCache = null; - } - this.fireContentsChanged(this, -1, -1); - } - } - - private synchronized PlatformKey[] getPlatformNames() { - if (this.platformNamesCache == null) { - JavaPlatform[] platforms = pm.getPlatforms(null, new Specification("j2se",null)); //NOI18N - Set orderedNames = new TreeSet(); - boolean activeFound = false; - for (int i=0; i< platforms.length; i++) { - if (platforms[i].getInstallFolders().size()>0) { - PlatformKey pk = new PlatformKey(platforms[i]); - orderedNames.add(pk); - if (!activeFound && initialPlatform != null) { - String antName = platforms[i].getProperties().get("platform.ant.name"); //NOI18N - if (initialPlatform.equals(antName)) { - if (this.selectedPlatform == null) { - this.selectedPlatform = pk; - initialPlatform = null; - } - activeFound = true; - } - } - } - } - if (!activeFound) { - if (initialPlatform == null) { - if (this.selectedPlatform == null || !orderedNames.contains(this.selectedPlatform)) { - this.selectedPlatform = new PlatformKey(JavaPlatformManager.getDefault().getDefaultPlatform()); - } - } else { - PlatformKey pk = new PlatformKey(this.initialPlatform); - orderedNames.add(pk); - if (this.selectedPlatform == null) { - this.selectedPlatform = pk; - } - } - } - this.platformNamesCache = orderedNames.toArray(new PlatformKey[orderedNames.size()]); - } - return this.platformNamesCache; - } - - } - - private static class PlatformListCellRenderer implements ListCellRenderer { - - private final ListCellRenderer delegate; - - public PlatformListCellRenderer() { - this.delegate = HtmlRenderer.createRenderer(); - } - - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - String name; - if (value == null) { - name = ""; //NOI18N - } else { - assert value instanceof PlatformKey : "Wrong model"; //NOI18N - PlatformKey key = (PlatformKey) value; - if (key.isBroken()) { - name = "" + //NOI18N - NbBundle.getMessage(PlatformUiSupport.class,"TXT_BrokenPlatformFmt", key.getDisplayName()); - } else { - name = key.getDisplayName(); - } - } - return this.delegate.getListCellRendererComponent(list, name, index, isSelected, cellHasFocus); - } - } - - private static class SourceLevelComboBoxModel extends AbstractListModel implements ComboBoxModel, ListDataListener { - private static final long serialVersionUID = 1L; - - private static final String VERSION_PREFIX = "1."; //The version prefix // NOI18N - private static final int INITIAL_VERSION_MINOR = 2; //1.2 - // if project is JAVA EE 5 show only 1.5 and higher - private static final int INITIAL_VERSION_MINOR_JAVA_EE_5 = 5; // 1.5 - - private SpecificationVersion selectedSourceLevel; - private SpecificationVersion originalSourceLevel; - private SourceLevelKey[] sourceLevelCache; - private final ComboBoxModel platformComboBoxModel; - private PlatformKey activePlatform; - private String j2eePlatform = null; - - public SourceLevelComboBoxModel(ComboBoxModel platformComboBoxModel, String initialSourceLevel, String initialTargetLevel) { - this.platformComboBoxModel = platformComboBoxModel; - this.activePlatform = (PlatformKey) this.platformComboBoxModel.getSelectedItem(); - this.platformComboBoxModel.addListDataListener(this); - if (initialSourceLevel != null && initialSourceLevel.length()>0) { - try { - originalSourceLevel = new SpecificationVersion (initialSourceLevel); - } catch (NumberFormatException nfe) { - // If the javac.source has invalid value, do not preselect and log it. - LOGGER.log(Level.INFO, "Invalid javac.source: " + initialSourceLevel); - } - } - if (initialTargetLevel != null && initialTargetLevel.length() > 0) { - try { - SpecificationVersion originalTargetLevel = new SpecificationVersion (initialTargetLevel); - if (this.originalSourceLevel == null || this.originalSourceLevel.compareTo(originalTargetLevel)<0) { - this.originalSourceLevel = originalTargetLevel; - } - } catch (NumberFormatException nfe) { - //If the javac.target has invalid value, do not preselect and log it - LOGGER.warning("Invalid javac.target: "+initialTargetLevel); //NOI18N - } - } - this.selectedSourceLevel = this.originalSourceLevel; - } - - public SourceLevelComboBoxModel(ComboBoxModel platformComboBoxModel, String initialSourceLevel, String initialTargetLevel, String j2eePlatform) { - this(platformComboBoxModel, initialSourceLevel, initialTargetLevel); - this.j2eePlatform = j2eePlatform; - } - - public int getSize() { - SourceLevelKey[] sLevels = getSourceLevels(); - return sLevels.length; - } - - public Object getElementAt(int index) { - SourceLevelKey[] sLevels = getSourceLevels(); - assert index >=0 && index< sLevels.length; - return sLevels[index]; - } - - public Object getSelectedItem () { - SourceLevelKey[] keys = getSourceLevels(); - for (int i=0; i0 && - !shouldChangePlatform(selectedSourceLevel, version)) { - //Restore original - this.platformComboBoxModel.setSelectedItem(this.activePlatform); - return; - } - else { - this.originalSourceLevel = null; - } - } - this.activePlatform = selectedPlatform; - resetCache(); - } - - private void resetCache() { - synchronized (this) { - this.sourceLevelCache = null; - } - this.fireContentsChanged(this, -1, -1); - } - - private SourceLevelKey[] getSourceLevels() { - if (this.sourceLevelCache == null) { - PlatformKey selectedPlatform = (PlatformKey) this.platformComboBoxModel.getSelectedItem(); - JavaPlatform platform = getPlatform(selectedPlatform); - List sLevels = new ArrayList(); - //If platform == null broken platform, the source level range is unknown - //The source level combo box should be empty and disabled - boolean selSourceLevelValid = false; - if (platform != null) { - SpecificationVersion version = platform.getSpecification().getVersion(); - int index = INITIAL_VERSION_MINOR; - // #71619 - source level lower than 1.5 won't be shown for Java EE 5 project - if (j2eePlatform != null && j2eePlatform.equals(AppClientProjectProperties.JAVA_EE_5)) { - index = INITIAL_VERSION_MINOR_JAVA_EE_5; - } - SpecificationVersion template = new SpecificationVersion (VERSION_PREFIX + Integer.toString (index++)); - boolean origSourceLevelValid = false; - - while (template.compareTo(version)<=0) { - if (template.equals(this.originalSourceLevel)) { - origSourceLevelValid = true; - } - if (template.equals(this.selectedSourceLevel)) { - selSourceLevelValid = true; - } - sLevels.add (new SourceLevelKey (template)); - template = new SpecificationVersion (VERSION_PREFIX + Integer.toString (index++)); - } - if (this.originalSourceLevel != null && !origSourceLevelValid) { - if (originalSourceLevel.equals(this.selectedSourceLevel)) { - selSourceLevelValid = true; - } - sLevels.add (new SourceLevelKey(this.originalSourceLevel,true)); - } - } - this.sourceLevelCache = sLevels.toArray(new SourceLevelKey[sLevels.size()]); - if (!selSourceLevelValid) { - this.selectedSourceLevel = this.sourceLevelCache.length == 0 ? - null : this.sourceLevelCache[this.sourceLevelCache.length-1].getSourceLevel(); - } - } - return this.sourceLevelCache; - } - - private static boolean shouldChangePlatform(SpecificationVersion selectedSourceLevel, SpecificationVersion platformSourceLevel) { - JButton changeOption = new JButton(NbBundle.getMessage(PlatformUiSupport.class, "CTL_ChangePlatform")); - changeOption.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PlatformUiSupport.class, "AD_ChangePlatform")); - String message = MessageFormat.format(NbBundle.getMessage(PlatformUiSupport.class,"TXT_ChangePlatform"),new Object[] { - selectedSourceLevel.toString(), - platformSourceLevel.toString(), - }); - return DialogDisplayer.getDefault().notify( - new NotifyDescriptor(message, - NbBundle.getMessage(PlatformUiSupport.class,"TXT_ChangePlatformTitle"), - NotifyDescriptor.DEFAULT_OPTION, - NotifyDescriptor.WARNING_MESSAGE, - new Object[] { - changeOption, - NotifyDescriptor.CANCEL_OPTION - }, - changeOption)) == changeOption; - } - } - - private static class SourceLevelListCellRenderer implements ListCellRenderer { - - ListCellRenderer delegate; - - public SourceLevelListCellRenderer() { - this.delegate = HtmlRenderer.createRenderer(); - } - - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - String message; - if (value == null) { - message = ""; //NOI18N - } - else { - assert value instanceof SourceLevelKey; - SourceLevelKey key = (SourceLevelKey) value; - if (key.isBroken()) { - message = "" + //NOI18N - NbBundle.getMessage(PlatformUiSupport.class,"TXT_InvalidSourceLevel",key.getDisplayName()); - } - else { - message = key.getDisplayName(); - } - } - return this.delegate.getListCellRendererComponent(list, message, index, isSelected, cellHasFocus); - } - } - -} diff --git a/j2ee.ejbjarproject/nbproject/project.xml b/j2ee.ejbjarproject/nbproject/project.xml --- a/j2ee.ejbjarproject/nbproject/project.xml +++ b/j2ee.ejbjarproject/nbproject/project.xml @@ -195,6 +195,15 @@ made subject to such option by the copyr 4 1.29 + + + + org.netbeans.modules.java.api.common + + + + 0-1 + 1.0 diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/EjbJarFileBuiltQuery.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/EjbJarFileBuiltQuery.java deleted file mode 100644 --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/EjbJarFileBuiltQuery.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.j2ee.ejbjarproject; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; -import org.openide.filesystems.FileObject; -import org.netbeans.api.queries.FileBuiltQuery; -import org.netbeans.spi.queries.FileBuiltQueryImplementation; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; - - -public class EjbJarFileBuiltQuery implements FileBuiltQueryImplementation, PropertyChangeListener { - - private FileBuiltQueryImplementation delegate; - private final AntProjectHelper helper; - private final PropertyEvaluator evaluator; - private final SourceRoots sourceRoots; - private final SourceRoots testRoots; - - EjbJarFileBuiltQuery (AntProjectHelper helper, PropertyEvaluator evaluator, - SourceRoots sourceRoots, SourceRoots testRoots) { - this.helper = helper; - this.evaluator = evaluator; - this.sourceRoots = sourceRoots; - this.testRoots = testRoots; - } - - public synchronized FileBuiltQuery.Status getStatus(FileObject file) { - if (this.delegate == null) { - this.delegate = createDelegate (); - } - return this.delegate.getStatus (file); - } - - private FileBuiltQueryImplementation createDelegate () { - String[] srcRoots = this.sourceRoots.getRootProperties(); - String[] tstRoots = this.testRoots.getRootProperties(); - String[] from = new String [srcRoots.length + tstRoots.length]; - String[] to = new String [srcRoots.length + tstRoots.length]; - for (int i=0; i< srcRoots.length; i++) { - from[i] = "${" + srcRoots[i] + "}/*.java"; // NOI18N - to[i] = "${" + EjbJarProjectProperties.BUILD_CLASSES_DIR + "}/*.class"; // NOI18N - } - for (int i=0; i() { - public Integer run() { - synchronized (EjbJarSharabilityQuery.this) { - if (delegate == null) { - delegate = createDelegate (); - } - return new Integer(delegate.getSharability (file)); - } - } - }); - return ret.intValue(); - } - - public void propertyChange(PropertyChangeEvent evt) { - if (SourceRoots.PROP_ROOT_PROPERTIES.equals(evt.getPropertyName())) { - synchronized (this) { - this.delegate = null; - } - } - } - - private SharabilityQueryImplementation createDelegate () { - String[] srcProps = srcRoots.getRootProperties(); - String[] testProps = testRoots.getRootProperties(); - String[] props = new String [srcProps.length + testProps.length + 1]; - for (int i=0; i sourceRootProperties; - private List sourceRootNames; - private List sourceRoots; - private List sourceRootURLs; - private final PropertyChangeSupport support; - private final ProjectMetadataListener listener; - private final boolean isTest; - private final File projectDir; - - /** - * Creates new SourceRoots - * @param helper - * @param evaluator - * @param elementName the name of XML element under which are declared the roots - * @param newRootNameTemplate template for new property name of source root - */ - SourceRoots (UpdateHelper helper, PropertyEvaluator evaluator, ReferenceHelper refHelper, String elementName, boolean isTest, String newRootNameTemplate) { - assert helper != null && evaluator != null && refHelper != null && elementName != null && newRootNameTemplate != null; - this.helper = helper; - this.evaluator = evaluator; - this.refHelper = refHelper; - this.elementName = elementName; - this.isTest = isTest; - this.newRootNameTemplate = newRootNameTemplate; - this.projectDir = FileUtil.toFile(this.helper.getAntProjectHelper().getProjectDirectory()); - this.support = new PropertyChangeSupport(this); - this.listener = new ProjectMetadataListener(); - this.evaluator.addPropertyChangeListener (WeakListeners.propertyChange(this.listener,this.evaluator)); - this.helper.getAntProjectHelper().addAntProjectListener(WeakListeners.create(AntProjectListener.class, this.listener, this.helper)); - } - - - /** - * Returns the display names of soruce roots - * The returned array has the same length as an array returned by the getRootProperties. - * It may contain empty strings but not null. - * @return an array of String - */ - public String[] getRootNames () { - return ProjectManager.mutex().readAccess(new Mutex.Action() { - public String[] run() { - synchronized (SourceRoots.this) { - if (sourceRootNames == null) { - readProjectMetadata(); - } - } - return sourceRootNames.toArray(new String[sourceRootNames.size()]); - } - }); - } - - /** - * Returns names of Ant properties in the project.properties file holding the source roots. - * @return an array of String - */ - public String[] getRootProperties () { - return ProjectManager.mutex().readAccess(new Mutex.Action() { - public String[] run() { - synchronized (SourceRoots.this) { - if (sourceRootProperties == null) { - readProjectMetadata(); - } - } - return sourceRootProperties.toArray (new String[sourceRootProperties.size()]); - } - }); - } - - /** - * Returns the source roots - * @return an array of FileObject - */ - public FileObject[] getRoots () { - return ProjectManager.mutex().readAccess(new Mutex.Action() { - public FileObject[] run () { - synchronized (this) { - //Local caching - if (sourceRoots == null) { - String[] srcProps = getRootProperties(); - List result = new ArrayList(); - for (int i = 0; i() { - public URL[] run () { - synchronized (this) { - //Local caching - if (sourceRootURLs == null) { - String[] srcProps = getRootProperties(); - List result = new ArrayList(); - for (int i = 0; iunmodifiableList(result); - } - } - return sourceRootURLs.toArray(new URL[sourceRootURLs.size()]); - } - }); - } - - /** - * Adds PropertyChangeListener - * @param listener - */ - public void addPropertyChangeListener (PropertyChangeListener listener) { - this.support.addPropertyChangeListener (listener); - } - - /** - * Removes PropertyChangeListener - * @param listener - */ - public void removePropertyChangeListener (PropertyChangeListener listener) { - this.support.removePropertyChangeListener (listener); - } - - - /** - * Replaces the current roots by the new ones - * @param roots the URLs of new roots - * @param labels the names of roots - */ - public void putRoots (final URL[] roots, final String[] labels) { - ProjectManager.mutex().writeAccess( - new Runnable() { - public void run() { - String[] originalProps = getRootProperties(); - URL[] originalRoots = getRootURLs(); - Map oldRoots2props = new HashMap(); - for (int i=0; i newRoots2lab = new HashMap(); - for (int i=0; i0) { - Element root = (Element) rootsNodes.item(0); - ownerElement.removeChild(root); - } - //Remove all unused root properties - List newRoots = Arrays.asList(roots); - Map propsToRemove = new HashMap(oldRoots2props); - propsToRemove.keySet().removeAll(newRoots); - EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - for (Iterator it = propsToRemove.values().iterator(); it.hasNext();) { - String propName = (String) it.next (); - props.remove(propName); - } - helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,props); - //Add the new roots - Document doc = ownerElement.getOwnerDocument(); - oldRoots2props.keySet().retainAll(newRoots); - for (Iterator it = newRoots.iterator(); it.hasNext();) { - URL newRoot = (URL) it.next (); - String rootName = oldRoots2props.get(newRoot); - if (rootName == null) { - //Root is new generate property for it - props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - String[] names = newRoot.getPath().split("/"); //NOI18N - rootName = MessageFormat.format(newRootNameTemplate,new Object[]{names[names.length-1],""}); //NOI18N - int rootIndex = 1; - while (props.containsKey(rootName)) { - rootIndex++; - rootName = MessageFormat.format(newRootNameTemplate,new Object[]{names[names.length-1],new Integer(rootIndex)}); - } - File f = FileUtil.normalizeFile(new File(URI.create(newRoot.toExternalForm()))); - File projDir = FileUtil.toFile(helper.getAntProjectHelper().getProjectDirectory()); - String path = f.getAbsolutePath(); - String prjPath = projDir.getAbsolutePath()+File.separatorChar; - if (path.startsWith(prjPath)) { - path = path.substring(prjPath.length()); - } - else { - path = refHelper.createForeignFileReference(f, JavaProjectConstants.SOURCES_TYPE_JAVA); - props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - } - props.put(rootName,path); - helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,props); - } - Element newRootNode = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "root"); //NOI18N - newRootNode.setAttribute("id",rootName); //NOI18N - String label = newRoots2lab.get(newRoot); - if (label != null && label.length()>0 && !label.equals (getRootDisplayName(null,rootName))) { //NOI18N - newRootNode.setAttribute("name",label); //NOI18N - } - ownerElement.appendChild (newRootNode); - } - helper.putPrimaryConfigurationData(cfgEl,true); - } - } - ); - } - - /** - * Translates root name into display name of source/test root - * @param rootName the name of root got from {@link SourceRoots#getRootNames} - * @param propName the name of property the root is stored in - * @return the label to be displayed - */ - public String getRootDisplayName (String rootName, String propName) { - if (rootName == null || rootName.length() ==0) { - //If the prop is src.dir use the default name - if (isTest && "test.src.dir".equals(propName)) { //NOI18N - rootName = DEFAULT_TEST_LABEL; - } - else if (!isTest && "src.dir".equals(propName)) { //NOI18N - rootName = DEFAULT_SOURCE_LABEL; - } - else { - //If the name is not given, it should be either a relative path in the project dir - //or absolute path when the root is not under the project dir - String propValue = evaluator.getProperty(propName); - File sourceRoot = propValue == null ? null : helper.getAntProjectHelper().resolveFile(propValue); - rootName = createInitialDisplayName(sourceRoot); - } - } - return rootName; - } - - /** - * Creates initial display name of source/test root - * @param sourceRoot the source root - * @return the label to be displayed - */ - public String createInitialDisplayName (File sourceRoot) { - String rootName; - if (sourceRoot != null) { - String srPath = sourceRoot.getAbsolutePath(); - String pdPath = projectDir.getAbsolutePath() + File.separatorChar; - if (srPath.startsWith(pdPath)) { - rootName = srPath.substring(pdPath.length()); - } - else { - rootName = sourceRoot.getAbsolutePath(); - } - } - else { - rootName = isTest ? DEFAULT_TEST_LABEL : DEFAULT_SOURCE_LABEL; - } - return rootName; - } - - private void resetCache (boolean isXMLChange, String propName) { - boolean fire = false; - synchronized (this) { - //In case of change reset local cache - if (isXMLChange) { - this.sourceRootProperties = null; - this.sourceRootNames = null; - this.sourceRoots = null; - this.sourceRootURLs = null; - fire = true; - } else if (propName == null || (sourceRootProperties != null && sourceRootProperties.contains(propName))) { - this.sourceRoots = null; - this.sourceRootURLs = null; - fire = true; - } - } - if (fire) { - if (isXMLChange) { - this.support.firePropertyChange (PROP_ROOT_PROPERTIES,null,null); - } - this.support.firePropertyChange (PROP_ROOTS,null,null); - } - } - - private void readProjectMetadata () { - Element cfgEl = helper.getPrimaryConfigurationData(true); - NodeList nl = cfgEl.getElementsByTagNameNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, elementName); - assert nl.getLength() == 0 || nl.getLength() == 1 : "Illegal project.xml"; //NOI18N - List rootProps = new ArrayList(); - List rootNames = new ArrayList(); - // It can be 0 in the case when the project is created by EjbJarProjectGenerator and not yet customized - if (nl.getLength()==1) { - NodeList roots = ((Element)nl.item(0)).getElementsByTagNameNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "root"); //NOI18N - for (int i=0; i 0 : "Illegal project.xml"; - rootProps.add(value); - value = root.getAttribute("name"); //NOI18N - rootNames.add (value); - } - } - this.sourceRootProperties = Collections.unmodifiableList(rootProps); - this.sourceRootNames = Collections.unmodifiableList(rootNames); - } - - private class ProjectMetadataListener implements PropertyChangeListener,AntProjectListener { - - public void propertyChange(PropertyChangeEvent evt) { - resetCache (false,evt.getPropertyName()); - } - - public void configurationXmlChanged(AntProjectEvent ev) { - resetCache (true,null); - } - - public void propertiesChanged(AntProjectEvent ev) { - //Handled by propertyChange - } - } - - public boolean isTest() { - return isTest; - } -} diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/UpdateHelper.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/UpdateHelper.java deleted file mode 100644 --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/UpdateHelper.java +++ /dev/null @@ -1,448 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.j2ee.ejbjarproject; - -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import org.netbeans.modules.j2ee.ejbjarproject.api.EjbJarProjectGenerator; -import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; -import org.w3c.dom.Comment; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.util.NbBundle; -import org.openide.util.Mutex; -import org.netbeans.api.project.Project; -import org.netbeans.api.project.ProjectManager; -import org.netbeans.api.project.libraries.LibraryManager; -import org.netbeans.spi.project.AuxiliaryConfiguration; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.EditableProperties; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.util.Exceptions; - - -/** - * Proxy for the AntProjectHelper which defers the update of the project metadata - * to explicit user action. Currently it is hard coded for update from - * "http://www.netbeans.org/ns/j2se-project/1" to "http://www.netbeans.org/ns/j2se-project/2". - * In future it should define plugable SPI. - */ -public class UpdateHelper { - - private final Project project; - private final AntProjectHelper helper; - private final AuxiliaryConfiguration cfg; - private final GeneratedFilesHelper genFileHelper; - private final Notifier notifier; - private boolean alreadyAskedInWriteAccess; - private Boolean isCurrent; - private Element cachedElement; - - private static final String BUILD_NUMBER = System.getProperty("netbeans.buildnumber"); // NOI18N - private static final String INCLUDED_LIBRARY_ELEMENT = "included-library"; //NOI18N - private static final String MINIMUM_ANT_VERSION_ELEMENT = "minimum-ant-version"; // NOI18N - private static final String ATTR_FILES = "files"; //NOI18N - private static final String ATTR_DIRS = "dirs"; //NOI18N - - /** - * Creates new UpdateHelper - * @param project - * @param helper AntProjectHelper - * @param cfg AuxiliaryConfiguration - * @param genFileHelper GeneratedFilesHelper - * @param notifier used to ask user about project update - */ - UpdateHelper (Project project, AntProjectHelper helper, AuxiliaryConfiguration cfg, GeneratedFilesHelper genFileHelper, Notifier notifier) { - assert project != null && helper != null && cfg != null && genFileHelper != null && notifier != null; - this.project = project; - this.helper = helper; - this.cfg = cfg; - this.genFileHelper = genFileHelper; - this.notifier = notifier; - } - - /** - * Returns the AntProjectHelper.getProperties(), {@link AntProjectHelper#getProperties(String)} - * @param path a relative URI in the project directory. - * @return a set of properties - */ - public EditableProperties getProperties (String path) { - //Properties are the same in both j2seproject/1 and j2seproject/2 - return this.helper.getProperties(path); - } - - /** - * In the case that the project is of current version or the properties are not {@link AntProjectHelper#PROJECT_PROPERTIES_PATH} - * it calls AntProjectHelper.putProperties(), {@link AntProjectHelper#putProperties(String, EditableProperties)} - * otherwise it asks user to updata project. If the user agrees with the project update, it does the update and calls - * AntProjectHelper.putProperties(). - * @param path a relative URI in the project directory. - * @param props a set of properties - */ - public void putProperties(final String path, final EditableProperties props) { - ProjectManager.mutex().writeAccess(new Runnable() { - public void run() { - if (isCurrent() || !AntProjectHelper.PROJECT_PROPERTIES_PATH.equals(path)) { //Only project props should cause update - helper.putProperties(path,props); - } else if (canUpdate()) { - try { - saveUpdate(props); - helper.putProperties(path,props); - } catch (IOException ioe) { - Exceptions.printStackTrace(ioe); - } - } - } - }); - } - - /** - * In the case that the project is of current version or shared is false it delegates to - * AntProjectHelper.getPrimaryConfigurationData(), {@link AntProjectHelper#getPrimaryConfigurationData(boolean)}. - * Otherwise it creates an in memory update of shared configuration data and returns it. - * @param shared if true, refers to project.xml, else refers to - * private.xml - * @return the configuration data that is available - */ - public Element getPrimaryConfigurationData (final boolean shared) { - return ProjectManager.mutex().readAccess(new Mutex.Action(){ - public Element run() { - if (!shared || isCurrent()) { //Only shared props should cause update - return helper.getPrimaryConfigurationData(shared); - } - return getUpdatedSharedConfigurationData(); - } - }); - } - - /** - * In the case that the project is of current version or shared is false it calls AntProjectHelper.putPrimaryConfigurationData(), - * {@link AntProjectHelper#putPrimaryConfigurationData(Element, boolean)}. - * Otherwise it asks user to update the project. If the user agrees with the project update, it does the update and calls - * AntProjectHelper.PrimaryConfigurationData(). - * @param element the configuration data - * @param shared if true, refers to project.xml, else refers to - * private.xml - */ - public void putPrimaryConfigurationData(final Element element, final boolean shared) { - ProjectManager.mutex().writeAccess(new Runnable() { - public void run() { - if (!shared || isCurrent()) { - helper.putPrimaryConfigurationData(element, shared); - } else if (canUpdate()) { - try { - saveUpdate(null); - helper.putPrimaryConfigurationData(element, shared); - } catch (IOException ioe) { - Exceptions.printStackTrace(ioe); - } - } - } - }); - } - - /** - * Returns an AntProjectHelper. The helper may not be used for accessing/storing project metadata. - * For project metadata manipulation the UpdateHelper must be used. - * @return AntProjectHelper - */ - public AntProjectHelper getAntProjectHelper () { - return this.helper; - } - - /** - * Request an saving of update. If the project is not of current version the user will be asked to update the project. - * If the user agrees with an update the project is updated. - */ - public boolean requestSave () throws IOException{ - if (isCurrent()) { - return true; - } - if (!canUpdate()) { - return false; - } - saveUpdate (null); - return true; - } - - /** - * Returns true if the project is of current version. - * @return true if the project is of current version, otherwise false. - */ - public synchronized boolean isCurrent () { - if (this.isCurrent == null) { - this.isCurrent = this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2ee-ejbjarproject/1",true) == null - && this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2ee-ejbjarproject/2",true) == null? //NOI18N - Boolean.TRUE : Boolean.FALSE; - } - return isCurrent.booleanValue(); - } - - private boolean canUpdate () { - //Ask just once under a single write access - if (alreadyAskedInWriteAccess) { - return false; - } - else { - boolean canUpdate = this.notifier.canUpdate(); - if (!canUpdate) { - alreadyAskedInWriteAccess = true; - ProjectManager.mutex().postReadRequest(new Runnable() { - public void run() { - alreadyAskedInWriteAccess = false; - } - }); - } - return canUpdate; - } - } - - private void saveUpdate (EditableProperties props) throws IOException { - this.helper.putPrimaryConfigurationData(getUpdatedSharedConfigurationData(),true); - if (this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2ee-ejbjarproject/1",true) != null) { //NOI18N - //version 1 - this.cfg.removeConfigurationFragment("data","http://www.netbeans.org/ns/j2ee-ejbjarproject/1",true); //NOI18N - } else { - //version 2 - this.cfg.removeConfigurationFragment("data","http://www.netbeans.org/ns/j2ee-ejbjarproject/2",true); //NOI18N - } - - boolean putProps = false; - - // AB: fix for #55597: should not update the project without adding the properties - // update is only done once, so if we don't add the properties now, we don't get another chance to do so - if (props == null) { - props = getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - putProps = true; - } - - //add properties needed by 4.1 project - if(props != null) { - props.put("test.src.dir", "test"); //NOI18N - } - - if (putProps) { - helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); - } - - ProjectManager.getDefault().saveProject (this.project); - this.genFileHelper.refreshBuildScript(GeneratedFilesHelper.BUILD_IMPL_XML_PATH, UpdateHelper.class.getResource("resources/build-impl.xsl"), - true); - synchronized(this) { - this.isCurrent = Boolean.TRUE; - } - } - - private synchronized Element getUpdatedSharedConfigurationData () { - if (cachedElement == null) { - Element oldRoot = this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2ee-ejbjarproject/1",true); //NOI18N - - int version = 1; - if (oldRoot == null) { - version = 2; - oldRoot = this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2ee-ejbjarproject/2",true); //NOI18N - } - final String ns = version == 1 ? "http://www.netbeans.org/ns/j2ee-ejbjarproject/1" : "http://www.netbeans.org/ns/j2ee-ejbjarproject/2"; //NOI18N - - if (oldRoot != null) { - Document doc = oldRoot.getOwnerDocument(); - Element newRoot = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N - copyDocument (doc, oldRoot, newRoot); - if(version == 1) { - //1=>2 upgrade - Element sourceRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N - Element root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N - root.setAttribute ("id","src.dir"); //NOI18N - sourceRoots.appendChild(root); - newRoot.appendChild (sourceRoots); - Element testRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"test-roots"); //NOI18N - root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N - root.setAttribute ("id","test.src.dir"); //NOI18N - testRoots.appendChild (root); - newRoot.appendChild (testRoots); - } - if(version == 1 || version == 2) { - //2=>3 upgrade - NodeList libList = newRoot.getElementsByTagNameNS(ns, INCLUDED_LIBRARY_ELEMENT); - for (int i = 0; i < libList.getLength(); i++) { - if (libList.item(i).getNodeType() == Node.ELEMENT_NODE) { - Element library = (Element) libList.item(i); - String fileText = findText(library); - if (fileText.startsWith ("libs.")) { - String libName = fileText.substring(6, fileText.indexOf(".classpath")); //NOI18N - List/**/ roots = LibraryManager.getDefault().getLibrary(libName).getContent("classpath"); //NOI18N - ArrayList files = new ArrayList(); - ArrayList dirs = new ArrayList(); - for (Iterator it = roots.iterator(); it.hasNext();) { - URL rootUrl = (URL) it.next(); - FileObject root = org.openide.filesystems.URLMapper.findFileObject (rootUrl); - if ("jar".equals(rootUrl.getProtocol())) { //NOI18N - root = FileUtil.getArchiveFile (root); - } - if (root != null) { - if (root.isData()) { - files.add(root); - } else { - dirs.add(root); - } - } - } - if (files.size() > 0) { - library.setAttribute(ATTR_FILES, "" + files.size()); //NOI18N - } - if (dirs.size() > 0) { - library.setAttribute(ATTR_DIRS, "" + dirs.size()); //NOI18N - } - } - } - } - } - - cachedElement = updateMinAntVersion(newRoot, doc); - } - } - return cachedElement; - } - - private static void copyDocument (Document doc, Element from, Element to) { - NodeList nl = from.getChildNodes(); - int length = nl.getLength(); - for (int i=0; i< length; i++) { - Node node = nl.item (i); - Node newNode = null; - switch (node.getNodeType()) { - case Node.ELEMENT_NODE: - Element oldElement = (Element) node; - newNode = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName()); - //copy attributes - NamedNodeMap m = oldElement.getAttributes(); - Element newElement = (Element) newNode; - for (int index = 0; index < m.getLength(); index++) { - Node attr = m.item(index); - newElement.setAttribute(attr.getNodeName(), attr.getNodeValue()); - } - copyDocument(doc,oldElement,(Element)newNode); - break; - case Node.TEXT_NODE: - Text oldText = (Text) node; - newNode = doc.createTextNode(oldText.getData()); - break; - case Node.COMMENT_NODE: - Comment oldComment = (Comment) node; - newNode = doc.createComment(oldComment.getData()); - break; - } - if (newNode != null) { - to.appendChild (newNode); - } - } - } - - private static Element updateMinAntVersion (final Element root, final Document doc) { - NodeList list = root.getElementsByTagNameNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT); - if (list.getLength() == 1) { - Element me = (Element) list.item(0); - list = me.getChildNodes(); - if (list.getLength() == 1) { - me.replaceChild (doc.createTextNode(EjbJarProjectGenerator.MINIMUM_ANT_VERSION), list.item(0)); - return root; - } - } - assert false : "Invalid project file"; //NOI18N - return root; - } - - /** - * Creates an default Notifier. The default notifier displays a dialog warning user about project update. - * @return notifier - */ - public static Notifier createDefaultNotifier () { - return new Notifier() { - public boolean canUpdate() { - return DialogDisplayer.getDefault().notify( - new NotifyDescriptor.Confirmation (NbBundle.getMessage(UpdateHelper.class,"TXT_ProjectUpdate",BUILD_NUMBER), - NbBundle.getMessage(UpdateHelper.class,"TXT_ProjectUpdateTitle"), - NotifyDescriptor.YES_NO_OPTION)) == NotifyDescriptor.YES_OPTION; - } - }; - } - - /** - * Extract nested text from a node. - * Currently does not handle coalescing text nodes, CDATA sections, etc. - * @param parent a parent node - * @return the nested text, or null if none was found - */ - private static String findText(Node parent) { - NodeList l = parent.getChildNodes(); - for (int i = 0; i < l.getLength(); i++) { - if (l.item(i).getNodeType() == Node.TEXT_NODE) { - Text text = (Text)l.item(i); - return text.getNodeValue(); - } - } - return null; - } - - - /** - * Interface used by the UpdateHelper to ask user about - * the project update. - */ - public static interface Notifier { - /** - * Asks user to update the project - * @return true if the project should be updated - */ - public boolean canUpdate (); - } -} diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/UpdateProjectImpl.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/UpdateProjectImpl.java new file mode 100644 --- /dev/null +++ b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/UpdateProjectImpl.java @@ -0,0 +1,327 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.j2ee.ejbjarproject; + +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.api.project.libraries.LibraryManager; +import org.netbeans.modules.j2ee.ejbjarproject.api.EjbJarProjectGenerator; +import org.netbeans.modules.java.api.common.ant.UpdateImplementation; +import org.netbeans.spi.project.AuxiliaryConfiguration; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.EditableProperties; +import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.Mutex; +import org.openide.util.NbBundle; +import org.w3c.dom.Comment; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +/** + * + * @author Tomas Mysik + */ +public class UpdateProjectImpl implements UpdateImplementation { + + private static final String BUILD_NUMBER = System.getProperty("netbeans.buildnumber"); // NOI18N + private static final String INCLUDED_LIBRARY_ELEMENT = "included-library"; //NOI18N + private static final String MINIMUM_ANT_VERSION_ELEMENT = "minimum-ant-version"; // NOI18N + private static final String ATTR_FILES = "files"; //NOI18N + private static final String ATTR_DIRS = "dirs"; //NOI18N + + private final Project project; + private final AntProjectHelper helper; + private final AuxiliaryConfiguration cfg; + private final GeneratedFilesHelper genFileHelper; + private boolean alreadyAskedInWriteAccess; + private Boolean isCurrent; + private Element cachedElement; + + /** + * Creates new UpdateHelper + * @param project + * @param helper AntProjectHelper + * @param cfg AuxiliaryConfiguration + * @param genFileHelper GeneratedFilesHelper + * @param notifier used to ask user about project update + */ + UpdateProjectImpl(Project project, AntProjectHelper helper, AuxiliaryConfiguration cfg, + GeneratedFilesHelper genFileHelper) { + assert project != null && helper != null && cfg != null && genFileHelper != null; + this.project = project; + this.helper = helper; + this.cfg = cfg; + this.genFileHelper = genFileHelper; + } + + public boolean isCurrent() { + return ProjectManager.mutex().readAccess(new Mutex.Action() { + public Boolean run() { + synchronized (this) { + if (isCurrent == null) { + if ((cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2ee-ejbjarproject/1",true) != null) || + (cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2ee-ejbjarproject/2",true) != null)) { + isCurrent = Boolean.FALSE; + } else { + isCurrent = Boolean.TRUE; + } + } + return isCurrent; + } + } + }).booleanValue(); + } + + public boolean canUpdate() { + //Ask just once under a single write access + if (alreadyAskedInWriteAccess) { + return false; + } + else { + boolean canUpdate = showUpdateDialog(); + if (!canUpdate) { + alreadyAskedInWriteAccess = true; + ProjectManager.mutex().postReadRequest(new Runnable() { + public void run() { + alreadyAskedInWriteAccess = false; + } + }); + } + return canUpdate; + } + } + + public void saveUpdate(EditableProperties props) throws IOException { + this.helper.putPrimaryConfigurationData(getUpdatedSharedConfigurationData(),true); + if (this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2ee-ejbjarproject/1",true) != null) { //NOI18N + //version 1 + this.cfg.removeConfigurationFragment("data","http://www.netbeans.org/ns/j2ee-ejbjarproject/1",true); //NOI18N + } else { + //version 2 + this.cfg.removeConfigurationFragment("data","http://www.netbeans.org/ns/j2ee-ejbjarproject/2",true); //NOI18N + } + + boolean putProps = false; + + // AB: fix for #55597: should not update the project without adding the properties + // update is only done once, so if we don't add the properties now, we don't get another chance to do so + if (props == null) { + props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + putProps = true; + } + + //add properties needed by 4.1 project + if(props != null) { + props.put("test.src.dir", "test"); //NOI18N + } + + if (putProps) { + helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); + } + + ProjectManager.getDefault().saveProject (this.project); + this.genFileHelper.refreshBuildScript(GeneratedFilesHelper.BUILD_IMPL_XML_PATH, UpdateProjectImpl.class.getResource("resources/build-impl.xsl"), + true); + synchronized(this) { + this.isCurrent = Boolean.TRUE; + } + } + + public Element getUpdatedSharedConfigurationData() { + if (cachedElement == null) { + Element oldRoot = this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2ee-ejbjarproject/1",true); //NOI18N + + int version = 1; + if (oldRoot == null) { + version = 2; + oldRoot = this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2ee-ejbjarproject/2",true); //NOI18N + } + final String ns = version == 1 ? "http://www.netbeans.org/ns/j2ee-ejbjarproject/1" : "http://www.netbeans.org/ns/j2ee-ejbjarproject/2"; //NOI18N + + if (oldRoot != null) { + Document doc = oldRoot.getOwnerDocument(); + Element newRoot = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N + copyDocument (doc, oldRoot, newRoot); + if(version == 1) { + //1=>2 upgrade + Element sourceRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N + Element root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N + root.setAttribute ("id","src.dir"); //NOI18N + sourceRoots.appendChild(root); + newRoot.appendChild (sourceRoots); + Element testRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"test-roots"); //NOI18N + root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N + root.setAttribute ("id","test.src.dir"); //NOI18N + testRoots.appendChild (root); + newRoot.appendChild (testRoots); + } + if(version == 1 || version == 2) { + //2=>3 upgrade + NodeList libList = newRoot.getElementsByTagNameNS(ns, INCLUDED_LIBRARY_ELEMENT); + for (int i = 0; i < libList.getLength(); i++) { + if (libList.item(i).getNodeType() == Node.ELEMENT_NODE) { + Element library = (Element) libList.item(i); + String fileText = findText(library); + if (fileText.startsWith ("libs.")) { + String libName = fileText.substring(6, fileText.indexOf(".classpath")); //NOI18N + List/**/ roots = LibraryManager.getDefault().getLibrary(libName).getContent("classpath"); //NOI18N + ArrayList files = new ArrayList(); + ArrayList dirs = new ArrayList(); + for (Iterator it = roots.iterator(); it.hasNext();) { + URL rootUrl = (URL) it.next(); + FileObject root = org.openide.filesystems.URLMapper.findFileObject (rootUrl); + if ("jar".equals(rootUrl.getProtocol())) { //NOI18N + root = FileUtil.getArchiveFile (root); + } + if (root != null) { + if (root.isData()) { + files.add(root); + } else { + dirs.add(root); + } + } + } + if (files.size() > 0) { + library.setAttribute(ATTR_FILES, "" + files.size()); //NOI18N + } + if (dirs.size() > 0) { + library.setAttribute(ATTR_DIRS, "" + dirs.size()); //NOI18N + } + } + } + } + } + + cachedElement = updateMinAntVersion(newRoot, doc); + } + } + return cachedElement; + } + + public EditableProperties getUpdatedProjectProperties() { + // XXX no need to update? original comment was: Properties are the same in both j2seproject/1 and j2seproject/2 + return helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + } + + private static void copyDocument (Document doc, Element from, Element to) { + NodeList nl = from.getChildNodes(); + int length = nl.getLength(); + for (int i=0; i< length; i++) { + Node node = nl.item (i); + Node newNode = null; + switch (node.getNodeType()) { + case Node.ELEMENT_NODE: + Element oldElement = (Element) node; + newNode = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName()); + //copy attributes + NamedNodeMap m = oldElement.getAttributes(); + Element newElement = (Element) newNode; + for (int index = 0; index < m.getLength(); index++) { + Node attr = m.item(index); + newElement.setAttribute(attr.getNodeName(), attr.getNodeValue()); + } + copyDocument(doc,oldElement,(Element)newNode); + break; + case Node.TEXT_NODE: + Text oldText = (Text) node; + newNode = doc.createTextNode(oldText.getData()); + break; + case Node.COMMENT_NODE: + Comment oldComment = (Comment) node; + newNode = doc.createComment(oldComment.getData()); + break; + } + if (newNode != null) { + to.appendChild (newNode); + } + } + } + + private static Element updateMinAntVersion (final Element root, final Document doc) { + NodeList list = root.getElementsByTagNameNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT); + if (list.getLength() == 1) { + Element me = (Element) list.item(0); + list = me.getChildNodes(); + if (list.getLength() == 1) { + me.replaceChild (doc.createTextNode(EjbJarProjectGenerator.MINIMUM_ANT_VERSION), list.item(0)); + return root; + } + } + assert false : "Invalid project file"; //NOI18N + return root; + } + + /** + * Extract nested text from a node. + * Currently does not handle coalescing text nodes, CDATA sections, etc. + * @param parent a parent node + * @return the nested text, or null if none was found + */ + private static String findText(Node parent) { + NodeList l = parent.getChildNodes(); + for (int i = 0; i < l.getLength(); i++) { + if (l.item(i).getNodeType() == Node.TEXT_NODE) { + Text text = (Text)l.item(i); + return text.getNodeValue(); + } + } + return null; + } + + private boolean showUpdateDialog() { + return DialogDisplayer.getDefault().notify( + new NotifyDescriptor.Confirmation (NbBundle.getMessage(UpdateProjectImpl.class,"TXT_ProjectUpdate",BUILD_NUMBER), + NbBundle.getMessage(UpdateProjectImpl.class,"TXT_ProjectUpdateTitle"), + NotifyDescriptor.YES_NO_OPTION)) == NotifyDescriptor.YES_OPTION; + } +} diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/api/EjbJarProjectGenerator.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/api/EjbJarProjectGenerator.java --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/api/EjbJarProjectGenerator.java +++ b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/api/EjbJarProjectGenerator.java @@ -71,10 +71,10 @@ import org.netbeans.modules.j2ee.deploym import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject; import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProjectType; -import org.netbeans.modules.j2ee.ejbjarproject.UpdateHelper; import org.netbeans.modules.j2ee.ejbjarproject.Utils; import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; -import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.PlatformUiSupport; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; +import org.netbeans.modules.java.api.common.ui.PlatformUiSupport; import org.netbeans.modules.websvc.spi.webservices.WebServicesConstants; import org.openide.filesystems.FileSystem; import org.openide.filesystems.FileSystem.AtomicAction; @@ -510,7 +510,7 @@ public class EjbJarProjectGenerator { finalPlatformName = JavaPlatformManager.getDefault().getDefaultPlatform().getDisplayName(); } - PlatformUiSupport.storePlatform(ep, updateHelper, finalPlatformName, sourceLevel != null ? new SpecificationVersion(sourceLevel) : null); + PlatformUiSupport.storePlatform(ep, updateHelper, EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, finalPlatformName, sourceLevel != null ? new SpecificationVersion(sourceLevel) : null); helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); ProjectManager.getDefault().saveProject(ProjectManager.getDefault().findProject(helper.getProjectDirectory())); } catch (IOException e) { diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/classpath/ClassPathProviderImpl.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/classpath/ClassPathProviderImpl.java --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/classpath/ClassPathProviderImpl.java +++ b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/classpath/ClassPathProviderImpl.java @@ -47,7 +47,7 @@ import java.util.HashMap; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; -import org.netbeans.modules.j2ee.ejbjarproject.SourceRoots; +import org.netbeans.modules.java.api.common.SourceRoots; import org.netbeans.spi.java.classpath.ClassPathFactory; import org.netbeans.spi.java.classpath.ClassPathProvider; import org.netbeans.spi.java.project.classpath.support.ProjectClassPathSupport; diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/classpath/EjbJarProjectClassPathExtender.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/classpath/EjbJarProjectClassPathExtender.java --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/classpath/EjbJarProjectClassPathExtender.java +++ b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/classpath/EjbJarProjectClassPathExtender.java @@ -58,12 +58,12 @@ import org.netbeans.api.project.ant.AntA import org.netbeans.api.project.ant.AntArtifact; import org.netbeans.api.project.ProjectManager; import org.netbeans.api.project.Project; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.ReferenceHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.EditableProperties; -import org.netbeans.modules.j2ee.ejbjarproject.UpdateHelper; import org.openide.util.Exceptions; import org.openide.util.RequestProcessor; diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/classpath/SourcePathImplementation.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/classpath/SourcePathImplementation.java --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/classpath/SourcePathImplementation.java +++ b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/classpath/SourcePathImplementation.java @@ -51,8 +51,8 @@ import java.net.URL; import java.net.URL; import java.util.Iterator; import java.util.StringTokenizer; -import org.netbeans.modules.j2ee.ejbjarproject.SourceRoots; import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; +import org.netbeans.modules.java.api.common.SourceRoots; import org.netbeans.spi.java.classpath.ClassPathImplementation; import org.netbeans.spi.java.classpath.PathResourceImplementation; import org.netbeans.spi.java.classpath.support.ClassPathSupport; diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/queries/CompiledSourceForBinaryQuery.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/queries/CompiledSourceForBinaryQuery.java deleted file mode 100644 --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/queries/CompiledSourceForBinaryQuery.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.j2ee.ejbjarproject.queries; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.File; -import java.util.ArrayList; -import java.util.Iterator; -import javax.swing.event.ChangeEvent; -import org.netbeans.modules.j2ee.ejbjarproject.SourceRoots; -import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; -import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.openide.filesystems.FileObject; -import java.net.URL; -import java.net.MalformedURLException; -import javax.swing.event.ChangeListener; -import org.netbeans.api.java.queries.SourceForBinaryQuery; -import java.util.Map; -import java.util.HashMap; -import org.openide.filesystems.FileUtil; -import org.openide.util.Exceptions; - -/** - * Finds sources corresponding to binaries in a J2SE project. - * @author Jesse Glick, Tomas Zezula - */ -public class CompiledSourceForBinaryQuery implements SourceForBinaryQueryImplementation { - - private AntProjectHelper helper; - private final PropertyEvaluator evaluator; - private final SourceRoots sourceRoots; - private final SourceRoots testRoots; - private Map cache = new HashMap(); - - public CompiledSourceForBinaryQuery (AntProjectHelper helper,PropertyEvaluator evaluator, - SourceRoots srcRoots, SourceRoots testRoots) { - this.helper = helper; - this.evaluator = evaluator; - this.sourceRoots = srcRoots; - this.testRoots = testRoots; - } - - public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) { - if (FileUtil.getArchiveFile(binaryRoot) != null) { - binaryRoot = FileUtil.getArchiveFile(binaryRoot); - // XXX check whether this is really the root - } - SourceForBinaryQuery.Result res = cache.get(binaryRoot); - if (res != null) { - return res; - } - SourceRoots src = null; - if (hasSources(binaryRoot, EjbJarProjectProperties.BUILD_CLASSES_DIR)) { //NOI18N - src = this.sourceRoots; - } - else if (hasSources (binaryRoot, EjbJarProjectProperties.DIST_JAR)) { //NOI18N - src = this.sourceRoots; - } - else if (hasSources (binaryRoot, EjbJarProjectProperties.BUILD_TEST_CLASSES_DIR)) { //NOI18N - src = this.testRoots; - } - if (src == null) { - return null; - } - else { - res = new Result (src); - cache.put (binaryRoot, res); - return res; - } - } - - - private boolean hasSources (URL binaryRoot, String binaryProperty) { - try { - //TODO: Fix this. Use FileUtil.getArchiveFile. - if (binaryRoot.getProtocol().equals("jar")) { // NOI18N - // We are interested in the JAR file itself. - // Note that this impl therefore accepts *both* file:/tmp/foo.jar - // and jar:file:/tmp/foo.jar!/ as equivalent (like URLClassLoader). - String surl = binaryRoot.toExternalForm(); - if (surl.endsWith("!/")) { // NOI18N - binaryRoot = new URL(surl.substring(4, surl.length() - 2)); - } else if (surl.lastIndexOf("!/") == -1) { // NOI18N - // Legal?? - binaryRoot = new URL(surl.substring(4)); - } else { - // Some specific path, e.g. jar:file:/tmp/foo.jar!/foo/, - // which we do not support. - } - } - String outDir = helper.getStandardPropertyEvaluator ().getProperty (binaryProperty); - if (outDir != null) { - File f = helper.resolveFile (outDir); - URL url = f.toURI().toURL(); - if (!f.exists() && !f.getPath().toLowerCase().endsWith(".jar")) { // NOI18N - // non-existing - assert !url.toExternalForm().endsWith("/") : f; // NOI18N - url = new URL(url.toExternalForm() + "/"); // NOI18N - } - if (url.equals (binaryRoot)) { - return true; - } - } - } catch (MalformedURLException malformedURL) { - Exceptions.printStackTrace(malformedURL); - } - return false; - } - - private static class Result implements SourceForBinaryQuery.Result, PropertyChangeListener { - - private ArrayList listeners; - private SourceRoots sourceRoots; - - public Result (SourceRoots sourceRoots) { - this.sourceRoots = sourceRoots; - this.sourceRoots.addPropertyChangeListener(this); - } - - public FileObject[] getRoots () { - return this.sourceRoots.getRoots(); //No need to cache it, SourceRoots does - } - - public void addChangeListener (ChangeListener l) { - //TODO: Implement this if needed (source folder can be changed) - } - - public void removeChangeListener (ChangeListener l) { - //TODO: Implement this if needed (source folder can be changed) - } - - public void propertyChange(PropertyChangeEvent evt) { - if (SourceRoots.PROP_ROOTS.equals(evt.getPropertyName())) { - this.fireChange (); - } - } - - private void fireChange() { - Iterator it; - synchronized (this) { - if (this.listeners == null) { - return; - } - it = ((ArrayList)this.listeners.clone()).iterator(); - } - ChangeEvent event = new ChangeEvent(this); - while (it.hasNext()) { - ((ChangeListener)it.next()).stateChanged(event); - } - } - - } - -} diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/queries/EjbJarProjectEncodingQueryImpl.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/queries/EjbJarProjectEncodingQueryImpl.java deleted file mode 100644 --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/queries/EjbJarProjectEncodingQueryImpl.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.j2ee.ejbjarproject.queries; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.nio.charset.Charset; -import java.nio.charset.IllegalCharsetNameException; -import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; -import org.netbeans.spi.queries.FileEncodingQueryImplementation; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.openide.filesystems.FileObject; - -/** - * - * @author Tomas Zezula - */ -public class EjbJarProjectEncodingQueryImpl extends FileEncodingQueryImplementation implements PropertyChangeListener { - - - private final PropertyEvaluator eval; - private Charset cache; - - /** Creates a new instance of J2SEProjectEncodingQueryImpl */ - public EjbJarProjectEncodingQueryImpl(final PropertyEvaluator eval) { - assert eval != null; - this.eval = eval; - this.eval.addPropertyChangeListener(this); - } - - public Charset getEncoding(FileObject file) { - assert file != null; - synchronized (this) { - if (cache != null) { - return cache; - } - } - String enc = eval.getProperty(EjbJarProjectProperties.SOURCE_ENCODING); - synchronized (this) { - if (cache == null) { - try { - cache = enc == null ? Charset.defaultCharset() : Charset.forName(enc); - } catch (IllegalCharsetNameException exception) { - return null; - } - } - return cache; - } - } - - public void propertyChange(PropertyChangeEvent event) { - String propName = event.getPropertyName(); - if (propName == null || propName.equals(EjbJarProjectProperties.SOURCE_ENCODING)) { - synchronized (this) { - cache = null; - } - } - } - -} diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/queries/JavadocForBinaryQueryImpl.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/queries/JavadocForBinaryQueryImpl.java deleted file mode 100644 --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/queries/JavadocForBinaryQueryImpl.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.j2ee.ejbjarproject.queries; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import javax.swing.event.ChangeListener; -import org.netbeans.api.java.queries.JavadocForBinaryQuery; -import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; -import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.openide.filesystems.FileUtil; -import org.openide.util.ChangeSupport; -import org.openide.util.Exceptions; -import org.openide.util.WeakListeners; - - -/** - * Finds Javadoc (if it is built) corresponding to binaries in web project. - * @author David Konecny, Jesse Glick - */ -public class JavadocForBinaryQueryImpl implements JavadocForBinaryQueryImplementation { - - private final AntProjectHelper helper; - private final PropertyEvaluator evaluator; - - public JavadocForBinaryQueryImpl(AntProjectHelper helper, PropertyEvaluator evaluator) { - this.helper = helper; - this.evaluator = evaluator; - } - - public JavadocForBinaryQuery.Result findJavadoc(final URL binaryRoot) { - - class R implements JavadocForBinaryQuery.Result, PropertyChangeListener { - - private final ChangeSupport changeSupport = new ChangeSupport(this); - private URL[] result; - - public R () { - JavadocForBinaryQueryImpl.this.evaluator.addPropertyChangeListener (WeakListeners.propertyChange(this,JavadocForBinaryQueryImpl.this.evaluator)); - } - - public synchronized URL[] getRoots() { - if (this.result == null) { - String javadocDir = evaluator.getProperty(EjbJarProjectProperties.DIST_JAVADOC_DIR); - if (javadocDir != null) { - File f = helper.resolveFile(javadocDir); - try { - URL url = f.toURI().toURL(); - if (!f.exists()) { - assert !url.toExternalForm().endsWith("/") : f; // NOI18N - url = new URL(url.toExternalForm() + "/"); // NOI18N - } - this.result = new URL[] {url}; - } catch (MalformedURLException e) { - this.result = new URL[0]; - Exceptions.printStackTrace(e); - } - } - else { - this.result = new URL[0]; - } - } - return this.result; - } - public void addChangeListener(final ChangeListener l) { - assert l != null; - changeSupport.addChangeListener(l); - } - public void removeChangeListener(final ChangeListener l) { - assert l != null; - changeSupport.removeChangeListener(l); - } - - public void propertyChange (final PropertyChangeEvent event) { - if (EjbJarProjectProperties.DIST_JAVADOC_DIR.equals(event.getPropertyName())) { - synchronized (this) { - result = null; - } - this.changeSupport.fireChange (); - } - } - } - if (isRootOwner(binaryRoot, EjbJarProjectProperties.BUILD_CLASSES_DIR) || isRootOwner (binaryRoot, EjbJarProjectProperties.DIST_JAR)) { - return new R(); - } - return null; - } - - private boolean isRootOwner (URL binaryRoot, String binaryProperty) { - try { - if (FileUtil.getArchiveFile(binaryRoot) != null) { - binaryRoot = FileUtil.getArchiveFile(binaryRoot); - // XXX check whether this is really the root - } - String outDir = evaluator.getProperty(binaryProperty); - if (outDir != null) { - File f = helper.resolveFile (outDir); - URL url = f.toURI().toURL(); - if (!f.exists() && !f.getPath().toLowerCase().endsWith(".jar")) { // NOI18N - assert !url.toExternalForm().endsWith("/") : f; // NOI18N - url = new URL(url.toExternalForm() + "/"); // NOI18N - } - return url.equals(binaryRoot) || - binaryRoot.toExternalForm().startsWith(url.toExternalForm()); - } - } catch (MalformedURLException malformedURL) { - Exceptions.printStackTrace(malformedURL); - } - return false; - } - -// private URL getJavadoc(URL binaryRoot, String binaryProperty, String javadocProperty) { -// try { -// if (FileUtil.getArchiveFile(binaryRoot) != null) { -// binaryRoot = FileUtil.getArchiveFile(binaryRoot); -// } -// String outDir = evaluator.getProperty(binaryProperty); -// if (outDir != null) { -// File f = helper.resolveFile (outDir); -// URL url = f.toURI().toURL(); -// if (!f.exists() && !f.getPath().toLowerCase().endsWith(".jar")) { -// assert !url.toExternalForm().endsWith("/") : f; -// url = new URL(url.toExternalForm() + "/"); -// } -// if (url.equals(binaryRoot) || -// binaryRoot.toExternalForm().startsWith(url.toExternalForm())) { -// String javadocDir = evaluator.getProperty(javadocProperty); -// if (javadocDir != null) { -// f = helper.resolveFile(javadocDir); -// return f.toURI().toURL(); -// } -// } -// } -// } catch (MalformedURLException malformedURL) { -// ErrorManager.getDefault().notify(malformedURL); -// } -// return null; -// } - -} diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/queries/SourceLevelQueryImpl.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/queries/SourceLevelQueryImpl.java deleted file mode 100644 --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/queries/SourceLevelQueryImpl.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.j2ee.ejbjarproject.queries; - -import org.netbeans.spi.java.queries.SourceLevelQueryImplementation; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.openide.filesystems.FileObject; - -/** - * Returns source level of project sources. - * @author David Konecny - */ -public class SourceLevelQueryImpl implements SourceLevelQueryImplementation { - - private final AntProjectHelper helper; - private final PropertyEvaluator evaluator; - - public SourceLevelQueryImpl(AntProjectHelper helper, PropertyEvaluator evaluator) { - this.helper = helper; - this.evaluator = evaluator; - } - - public String getSourceLevel(FileObject javaFile) { - String sl = evaluator.getProperty("javac.source"); //NOI18N - if (sl != null && sl.length() > 0) { - return sl; - } else { - return null; - } - } - -} diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/queries/UnitTestForSourceQueryImpl.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/queries/UnitTestForSourceQueryImpl.java deleted file mode 100644 --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/queries/UnitTestForSourceQueryImpl.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.j2ee.ejbjarproject.queries; -import java.net.URL; -import org.netbeans.api.project.FileOwnerQuery; -import org.netbeans.api.project.Project; -import org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation; -import org.netbeans.modules.j2ee.ejbjarproject.SourceRoots; -import org.openide.filesystems.FileObject; - -public class UnitTestForSourceQueryImpl implements MultipleRootsUnitTestForSourceQueryImplementation { - - private final SourceRoots sourceRoots; - private final SourceRoots testRoots; - - public UnitTestForSourceQueryImpl(SourceRoots sourceRoots, SourceRoots testRoots) { - this.sourceRoots = sourceRoots; - this.testRoots = testRoots; - } - - public URL[] findUnitTests(FileObject source) { - return find(source, sourceRoots, testRoots); // NOI18N - } - - public URL[] findSources(FileObject unitTest) { - return find(unitTest, testRoots, sourceRoots); // NOI18N - } - - private URL[] find(FileObject file, SourceRoots from, SourceRoots to) { - Project p = FileOwnerQuery.getOwner(file); - if (p == null) { - return null; - } - FileObject[] fromRoots = from.getRoots(); - for (int i = 0; i < fromRoots.length; i++) { - if (fromRoots[i].equals(file)) { - return to.getRootURLs(); - } - } - return null; - } - -} diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/EjbJarLogicalViewProvider.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/EjbJarLogicalViewProvider.java --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/EjbJarLogicalViewProvider.java +++ b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/EjbJarLogicalViewProvider.java @@ -67,7 +67,6 @@ import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener; import org.netbeans.api.java.platform.JavaPlatformManager; import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; -import org.netbeans.modules.j2ee.ejbjarproject.SourceRoots; import org.openide.nodes.*; import org.openide.util.*; @@ -91,7 +90,6 @@ import org.netbeans.api.project.SourceGr import org.netbeans.api.project.SourceGroup; import org.netbeans.api.project.Sources; import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; -import org.netbeans.modules.j2ee.ejbjarproject.UpdateHelper; import org.openide.filesystems.FileObject; import org.openide.loaders.DataFolder; import org.openide.util.lookup.Lookups; @@ -103,6 +101,8 @@ import org.netbeans.modules.j2ee.deploym import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject; import org.netbeans.modules.j2ee.spi.ejbjar.support.J2eeProjectView; +import org.netbeans.modules.java.api.common.SourceRoots; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.spi.project.ui.support.DefaultProjectOperations; import org.netbeans.spi.project.ui.support.NodeFactorySupport; import org.openide.filesystems.FileStateInvalidException; diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/LibrariesNodeFactory.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/LibrariesNodeFactory.java --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/LibrariesNodeFactory.java +++ b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/LibrariesNodeFactory.java @@ -53,13 +53,13 @@ import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener; import org.netbeans.api.project.Project; import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject; -import org.netbeans.modules.j2ee.ejbjarproject.SourceRoots; -import org.netbeans.modules.j2ee.ejbjarproject.UpdateHelper; import org.netbeans.modules.j2ee.ejbjarproject.classpath.ClassPathSupport; import org.netbeans.modules.j2ee.ejbjarproject.ui.SourceNodeFactory.PreselectPropertiesAction; import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.CustomizerLibraries; import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; import org.netbeans.modules.j2ee.ejbjarproject.ui.logicalview.libraries.LibrariesNode; +import org.netbeans.modules.java.api.common.SourceRoots; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.ReferenceHelper; import org.netbeans.spi.project.ui.support.NodeFactory; diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/CustomizerLibraries.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/CustomizerLibraries.java --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/CustomizerLibraries.java +++ b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/CustomizerLibraries.java @@ -55,6 +55,7 @@ import org.netbeans.api.java.platform.Pl import org.netbeans.api.java.platform.PlatformsCustomizer; import org.netbeans.modules.j2ee.ejbjarproject.classpath.ClassPathSupport; import org.netbeans.modules.j2ee.ejbjarproject.ui.EjbJarLogicalViewProvider; +import org.netbeans.modules.java.api.common.ui.PlatformUiSupport; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/CustomizerProviderImpl.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/CustomizerProviderImpl.java --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/CustomizerProviderImpl.java +++ b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/CustomizerProviderImpl.java @@ -52,7 +52,7 @@ import org.netbeans.api.project.Project; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectUtils; import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject; -import org.netbeans.modules.j2ee.ejbjarproject.UpdateHelper; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.ReferenceHelper; import org.netbeans.spi.project.ui.CustomizerProvider; diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/EjbJarProjectProperties.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/EjbJarProjectProperties.java --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/EjbJarProjectProperties.java +++ b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/EjbJarProjectProperties.java @@ -67,8 +67,6 @@ import org.netbeans.api.queries.Collocat import org.netbeans.api.queries.CollocationQuery; import org.netbeans.api.queries.FileEncodingQuery; import org.netbeans.modules.j2ee.deployment.devmodules.api.AntDeploymentHelper; -import org.netbeans.modules.j2ee.ejbjarproject.SourceRoots; -import org.netbeans.modules.j2ee.ejbjarproject.UpdateHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.openide.filesystems.FileUtil; import org.openide.util.MutexException; @@ -86,9 +84,13 @@ import org.netbeans.modules.j2ee.deploym import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; import org.netbeans.modules.j2ee.ejbjarproject.classpath.ClassPathSupport; import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject; +import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProjectType; import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProjectUtil; import org.netbeans.modules.j2ee.ejbjarproject.Utils; import org.netbeans.modules.j2ee.ejbjarproject.classpath.ClassPathSupport.Item; +import org.netbeans.modules.java.api.common.SourceRoots; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; +import org.netbeans.modules.java.api.common.ui.PlatformUiSupport; import org.netbeans.modules.websvc.spi.webservices.WebServicesConstants; import org.netbeans.spi.project.support.ant.PropertyUtils; import org.openide.filesystems.FileObject; @@ -304,7 +306,11 @@ public class EjbJarProjectProperties { RUN_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( projectProperties.get(RUN_TEST_CLASSPATH), null ) ); PLATFORM_MODEL = PlatformUiSupport.createPlatformComboBoxModel (evaluator.getProperty(JAVA_PLATFORM)); PLATFORM_LIST_RENDERER = PlatformUiSupport.createPlatformListCellRenderer(); - JAVAC_SOURCE_MODEL = PlatformUiSupport.createSourceLevelComboBoxModel (PLATFORM_MODEL, evaluator.getProperty(JAVAC_SOURCE), evaluator.getProperty(JAVAC_TARGET), evaluator.getProperty(J2EE_PLATFORM)); + PlatformUiSupport.JDK minimalSourceLevel = null; + if (evaluator.getProperty(J2EE_PLATFORM).equals(JAVA_EE_5)) { + minimalSourceLevel = PlatformUiSupport.JDK.VERSION_5; + } + JAVAC_SOURCE_MODEL = PlatformUiSupport.createSourceLevelComboBoxModel (PLATFORM_MODEL, evaluator.getProperty(JAVAC_SOURCE), evaluator.getProperty(JAVAC_TARGET), minimalSourceLevel); JAVAC_SOURCE_RENDERER = PlatformUiSupport.createSourceLevelListCellRenderer (); // CustomizerCompile @@ -392,7 +398,7 @@ public class EjbJarProjectProperties { projectProperties.setProperty( RUN_TEST_CLASSPATH, run_test_cp ); //Handle platform selection and javac.source javac.target properties - PlatformUiSupport.storePlatform (projectProperties, updateHelper, PLATFORM_MODEL.getSelectedItem(), JAVAC_SOURCE_MODEL.getSelectedItem()); + PlatformUiSupport.storePlatform (projectProperties, updateHelper, EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, PLATFORM_MODEL.getSelectedItem(), JAVAC_SOURCE_MODEL.getSelectedItem()); // Handle other special cases if ( NO_DEPENDENCIES_MODEL.isSelected() ) { // NOI18N diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/EjbJarSourceRootsUi.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/EjbJarSourceRootsUi.java --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/EjbJarSourceRootsUi.java +++ b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/EjbJarSourceRootsUi.java @@ -80,7 +80,7 @@ import org.netbeans.api.project.FileOwne import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectInformation; -import org.netbeans.modules.j2ee.ejbjarproject.SourceRoots; +import org.netbeans.modules.java.api.common.SourceRoots; import org.openide.DialogDisplayer; import org.openide.DialogDescriptor; import org.openide.filesystems.FileUtil; diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/PlatformUiSupport.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/PlatformUiSupport.java deleted file mode 100644 --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/customizer/PlatformUiSupport.java +++ /dev/null @@ -1,694 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.j2ee.ejbjarproject.ui.customizer; - -import java.awt.Component; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.AbstractListModel; -import javax.swing.ComboBoxModel; -import javax.swing.DefaultListCellRenderer; -import javax.swing.JButton; -import javax.swing.JList; -import javax.swing.ListCellRenderer; -import javax.swing.event.ListDataEvent; -import javax.swing.event.ListDataListener; -import org.netbeans.api.java.platform.JavaPlatform; -import org.netbeans.api.java.platform.JavaPlatformManager; -import org.netbeans.api.java.platform.Specification; -import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProjectType; -import org.netbeans.modules.j2ee.ejbjarproject.UpdateHelper; -import org.netbeans.spi.project.support.ant.EditableProperties; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.awt.HtmlRenderer; -import org.openide.modules.SpecificationVersion; -import org.openide.util.NbBundle; -import org.openide.util.WeakListeners; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -/** - * Support class for {@link JavaPlatform} manipulation in ejbjarproject customizer. - * @author tzezula - */ -public class PlatformUiSupport { - - private static final SpecificationVersion JDK_5 = new SpecificationVersion ("1.5"); //NOI18N - private static final SpecificationVersion JDK_6 = new SpecificationVersion ("1.6"); //NOI18N - private static final Logger LOGGER = Logger.getLogger(PlatformUiSupport.class.getName()); - - private PlatformUiSupport() { - } - - /** - * Creates {@link ComboBoxModel} of J2SE platforms. - * The model listens on the {@link JavaPlatformManager} and update its - * state according to changes - * @param activePlatform the active project's platform - * @return {@link ComboBoxModel} - */ - public static ComboBoxModel createPlatformComboBoxModel (String activePlatform) { - return new PlatformComboBoxModel (activePlatform); - } - - /** - * Creates a {@link ListCellRenderer} for rendering items of the {@link ComboBoxModel} - * created by the {@link PlatformUiSupport#createPlatformComboBoxModel} method. - * @return {@link ListCellRenderer} - */ - public static ListCellRenderer createPlatformListCellRenderer () { - return new PlatformListCellRenderer (); - } - - /** - * Like {@link #storePlatform}, but platformName may be null (in which case the default platform is used) - */ - public static void storePlatform (EditableProperties props, UpdateHelper helper, String platformName, SpecificationVersion sourceLevel) { - PlatformKey platformKey; - if (platformName != null) { - platformKey = new PlatformKey(PlatformUiSupport.findPlatform(platformName)); - } else { - platformKey = new PlatformKey(JavaPlatformManager.getDefault().getDefaultPlatform()); - } - storePlatform(props, helper, platformKey, sourceLevel == null ? null : new SourceLevelKey(sourceLevel)); - } - - /** - * Stores active platform, javac.source and javac.target into the project's metadata - * @param props project's shared properties - * @param helper to read/update project.xml - * @param platformKey the PatformKey got from the platform model - * @param sourceLevel source level - */ - public static void storePlatform (EditableProperties props, UpdateHelper helper, Object platformKey, Object sourceLevelKey) { - assert platformKey instanceof PlatformKey; - PlatformKey pk = (PlatformKey) platformKey; - JavaPlatform platform = getPlatform(pk); - //null means active broken (unresolved) platform, no need to do anything - if (platform != null) { - SpecificationVersion jdk13 = new SpecificationVersion ("1.3"); //NOI18N - String platformAntName = platform.getProperties().get("platform.ant.name"); //NOI18N - assert platformAntName != null; - props.put(EjbJarProjectProperties.JAVA_PLATFORM, platformAntName); - Element root = helper.getPrimaryConfigurationData(true); - boolean defaultPlatform = pk.isDefaultPlatform(); - boolean changed = false; - NodeList explicitPlatformNodes = root.getElementsByTagNameNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"explicit-platform"); //NOI18N - if (defaultPlatform) { - if (explicitPlatformNodes.getLength()==1) { - root.removeChild(explicitPlatformNodes.item(0)); - changed = true; - } - } - else { - Element explicitPlatform; - switch (explicitPlatformNodes.getLength()) { - case 0: - explicitPlatform = root.getOwnerDocument().createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "explicit-platform"); //NOI18N - NodeList sourceRootNodes = root.getElementsByTagNameNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N - assert sourceRootNodes.getLength() == 1 : "Broken project.xml file"; //NOI18N - root.insertBefore(explicitPlatform, sourceRootNodes.item(0)); - changed = true; - break; - case 1: - explicitPlatform = (Element)explicitPlatformNodes.item(0); - break; - default: - throw new AssertionError("Broken project.xml file"); //NOI18N - } - String explicitSourceAttrValue = explicitPlatform.getAttribute("explicit-source-supported"); //NOI18N - if (jdk13.compareTo(platform.getSpecification().getVersion())>=0 && - !"false".equals(explicitSourceAttrValue)) { //NOI18N - explicitPlatform.setAttribute("explicit-source-supported","false"); //NOI18N - changed = true; - } - else if (jdk13.compareTo(platform.getSpecification().getVersion())<0 && - !"true".equals(explicitSourceAttrValue)) { //NOI18N - explicitPlatform.setAttribute("explicit-source-supported","true"); //NOI18N - changed = true; - } - } - - SpecificationVersion sourceLevel; - if (sourceLevelKey == null) { - sourceLevel = platform.getSpecification().getVersion(); - } - else { - assert sourceLevelKey instanceof SourceLevelKey; - sourceLevel = ((SourceLevelKey)sourceLevelKey).getSourceLevel(); - } - String javacSource = sourceLevel.toString(); - String javacTarget = javacSource; - - //Issue #116490 - // Customizer value | -source | -targer - // JDK 1.2 1.2 1.1 - // JDK 1.3 1.3 1.1 - // JDK 1.4 1.4 1.4 - // JDK 5 1.5 1.5 - // JDK 6 1.5 1.6 - // JDK 7 1.7 1.7 - should bring a new language features - if (jdk13.compareTo(sourceLevel)>=0) { - javacTarget = "1.1"; //NOI18N - } - else if (JDK_6.equals(sourceLevel)) { - javacSource = JDK_5.toString(); //NOI18N - } - - // #89131: these levels are not actually distinct from 1.5. - if (javacSource.equals("1.6") || javacSource.equals("1.7")) { - javacSource = "1.5"; - } - if (!javacSource.equals(props.getProperty(EjbJarProjectProperties.JAVAC_SOURCE))) { - props.setProperty (EjbJarProjectProperties.JAVAC_SOURCE, javacSource); - } - if (!javacTarget.equals(props.getProperty(EjbJarProjectProperties.JAVAC_TARGET))) { - props.setProperty (EjbJarProjectProperties.JAVAC_TARGET, javacTarget); - } - - if (changed) { - helper.putPrimaryConfigurationData(root, true); - } - } - } - - public static JavaPlatform findPlatform(String displayName) { - JavaPlatform[] platforms = JavaPlatformManager.getDefault().getPlatforms(displayName, new Specification("j2se", null)); //NOI18N - return platforms.length == 0 ? null : platforms[0]; - } - - - /** - * Returns a {@link JavaPlatform} for an item obtained from the ComboBoxModel created by - * the {@link PlatformUiSupport#createComboBoxModel} method - * @param platformKey an item obtained from ComboBoxModel created by {@link PlatformUiSupport#createComboBoxModel} - * @return JavaPlatform or null in case when platform is broken - * @exception {@link IllegalArgumentException} is thrown in case when parameter in not an object created by - * platform combobox model. - */ - public static JavaPlatform getPlatform (Object platformKey) { - if (platformKey instanceof PlatformKey) { - return getPlatform ((PlatformKey)platformKey); - } - else { - throw new IllegalArgumentException (); - } - } - - /** - * Creates {@link ComboBoxModel} of source levels for active platform. - * The model listens on the platform's {@link ComboBoxModel} and update its - * state according to changes - * @param platformComboBoxModel the platform's model used for listenning - * @param initialSourceLevel initial source level value - * @param initialTargetLevel initial target level value - * @return {@link ComboBoxModel} of {@link SpecificationVersion} - */ - public static ComboBoxModel createSourceLevelComboBoxModel(ComboBoxModel platformComboBoxModel, String initialSourceLevel, String initialTargetLevel, String j2eePlatform) { - return new SourceLevelComboBoxModel(platformComboBoxModel, initialSourceLevel, initialTargetLevel, j2eePlatform); - } - - public static ListCellRenderer createSourceLevelListCellRenderer() { - return new SourceLevelListCellRenderer(); - } - - private static JavaPlatform getPlatform (PlatformKey platformKey) { - return platformKey.platform; - } - - /** - * This class represents a JavaPlatform in the {@link ListModel} - * created by the {@link PlatformUiSupport#createPlatformComboBoxModel} - * method. - */ - private static class PlatformKey implements Comparable { - - private String name; - private JavaPlatform platform; - - /** - * Creates a PlatformKey for a broken platform - * @param name the ant name of the broken platform - */ - public PlatformKey (String name) { - assert name != null; - this.name = name; - } - - /** - * Creates a PlatformKey for a platform - * @param platform the {@link JavaPlatform} - */ - public PlatformKey (JavaPlatform platform) { - assert platform != null; - this.platform = platform; - } - - public int compareTo(Object o) { - return this.getDisplayName().compareTo(((PlatformKey)o).getDisplayName()); - } - - @Override - public boolean equals (Object other) { - if (other instanceof PlatformKey) { - PlatformKey otherKey = (PlatformKey)other; - return (this.platform == null ? otherKey.platform == null : this.platform.equals(otherKey.platform)) && - otherKey.getDisplayName().equals (this.getDisplayName()); - } - else { - return false; - } - } - - @Override - public int hashCode () { - return getDisplayName ().hashCode (); - } - - @Override - public String toString () { - return getDisplayName (); - } - - public synchronized String getDisplayName () { - if (this.name == null) { - this.name = this.platform.getDisplayName(); - } - return this.name; - } - - public boolean isDefaultPlatform () { - if (this.platform == null) { - return false; - } - return this.platform.equals(JavaPlatformManager.getDefault().getDefaultPlatform()); - } - - public boolean isBroken () { - return this.platform == null; - } - } - - private static final class SourceLevelKey implements Comparable { - - final SpecificationVersion sourceLevel; - final boolean broken; - - public SourceLevelKey (final SpecificationVersion sourceLevel) { - this (sourceLevel, false); - } - - public SourceLevelKey (final SpecificationVersion sourceLevel, final boolean broken) { - assert sourceLevel != null : "Source level cannot be null"; //NOI18N - this.sourceLevel = sourceLevel; - this.broken = broken; - } - - public SpecificationVersion getSourceLevel () { - return this.sourceLevel; - } - - public boolean isBroken () { - return this.broken; - } - - public int compareTo (final Object other) { - assert other instanceof SourceLevelKey : "Illegal argument of SourceLevelKey.compareTo()"; //NOI18N - SourceLevelKey otherKey = (SourceLevelKey) other; - return this.sourceLevel.compareTo(otherKey.sourceLevel); - } - - public @Override boolean equals (final Object other) { - return (other instanceof SourceLevelKey) && - ((SourceLevelKey)other).sourceLevel.equals(this.sourceLevel); - } - - public @Override int hashCode () { - return this.sourceLevel.hashCode(); - } - - public @Override String toString () { - StringBuffer buffer = new StringBuffer (); - if (this.broken) { - buffer.append("Broken: "); //NOI18N - } - buffer.append(this.sourceLevel.toString()); - return buffer.toString(); - } - - public String getDisplayName () { - String _tmp = sourceLevel.toString(); - if (JDK_5.compareTo(sourceLevel)<=0) { - _tmp = _tmp.replaceFirst("^1\\.([5-9]|\\d\\d+)$", "$1"); //NOI18N - } - return NbBundle.getMessage(PlatformUiSupport.class, "LBL_JDK",_tmp); - } - - } - - private static class PlatformComboBoxModel extends AbstractListModel implements ComboBoxModel, PropertyChangeListener { - private static final long serialVersionUID = 41647580130743122L; - - private final JavaPlatformManager pm; - private PlatformKey[] platformNamesCache; - private String initialPlatform; - private PlatformKey selectedPlatform; - - public PlatformComboBoxModel (String initialPlatform) { - this.pm = JavaPlatformManager.getDefault(); - this.pm.addPropertyChangeListener(WeakListeners.propertyChange(this, this.pm)); - this.initialPlatform = initialPlatform; - } - - public int getSize () { - PlatformKey[] platformNames = getPlatformNames (); - return platformNames.length; - } - - public Object getElementAt (int index) { - PlatformKey[] platformNames = getPlatformNames (); - assert index >=0 && index< platformNames.length; - return platformNames[index]; - } - - public Object getSelectedItem () { - this.getPlatformNames(); //Force setting of selectedPlatform if it is not alredy done - return this.selectedPlatform; - } - - public void setSelectedItem (Object obj) { - this.selectedPlatform = (PlatformKey) obj; - this.fireContentsChanged(this, -1, -1); - } - - public void propertyChange (PropertyChangeEvent event) { - if (JavaPlatformManager.PROP_INSTALLED_PLATFORMS.equals(event.getPropertyName())) { - synchronized (this) { - this.platformNamesCache = null; - } - this.fireContentsChanged(this, -1, -1); - } - } - - private synchronized PlatformKey[] getPlatformNames () { - if (this.platformNamesCache == null) { - JavaPlatform[] platforms = pm.getPlatforms (null, new Specification("j2se",null)); //NOI18N - Set orderedNames = new TreeSet(); - boolean activeFound = false; - for (int i=0; i< platforms.length; i++) { - if (platforms[i].getInstallFolders().size()>0) { - PlatformKey pk = new PlatformKey(platforms[i]); - orderedNames.add (pk); - if (!activeFound && initialPlatform != null) { - String antName = platforms[i].getProperties().get("platform.ant.name"); //NOI18N - if (initialPlatform.equals(antName)) { - if (this.selectedPlatform == null) { - this.selectedPlatform = pk; - initialPlatform = null; - } - activeFound = true; - } - } - } - } - if (!activeFound) { - if (initialPlatform == null) { - if (this.selectedPlatform == null || !orderedNames.contains(this.selectedPlatform)) { - this.selectedPlatform = new PlatformKey (JavaPlatformManager.getDefault().getDefaultPlatform()); - } - } - else { - PlatformKey pk = new PlatformKey (this.initialPlatform); - orderedNames.add (pk); - if (this.selectedPlatform == null) { - this.selectedPlatform = pk; - } - } - } - this.platformNamesCache = orderedNames.toArray(new PlatformKey[orderedNames.size()]); - } - return this.platformNamesCache; - } - - } - - private static class PlatformListCellRenderer extends DefaultListCellRenderer { - private static final long serialVersionUID = 51419604163086358L; - - @Override - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - assert value instanceof PlatformKey : "Wrong model"; //NOI18N - PlatformKey key = (PlatformKey) value; - String name; - if (key.isBroken()) { - name = NbBundle.getMessage (PlatformUiSupport.class,"TXT_BrokenPlatformFmt", key.getDisplayName()); - } - else { - name = key.getDisplayName(); - } - return super.getListCellRendererComponent(list, name, index, isSelected, cellHasFocus); - } - } - - private static class SourceLevelComboBoxModel extends AbstractListModel implements ComboBoxModel, ListDataListener { - private static final long serialVersionUID = 108135581162238931L; - private static final String VERSION_PREFIX = "1."; //The version prefix - private static final int INITIAL_VERSION_MINOR = 2; //1.2 - // if project is JAVA EE 5 show only 1.5 and higher - private static final int INITIAL_VERSION_MINOR_JAVA_EE_5 = 5; // 1.5 - - private SpecificationVersion selectedSourceLevel; - private SpecificationVersion originalSourceLevel; - private SourceLevelKey[] sourceLevelCache; - private final ComboBoxModel platformComboBoxModel; - private PlatformKey activePlatform; - private String j2eePlatform = null; - - public SourceLevelComboBoxModel(ComboBoxModel platformComboBoxModel, String initialSourceLevel, String initialTargetLevel) { - this.platformComboBoxModel = platformComboBoxModel; - this.activePlatform = (PlatformKey) this.platformComboBoxModel.getSelectedItem(); - this.platformComboBoxModel.addListDataListener(this); - if (initialSourceLevel != null && initialSourceLevel.length()>0) { - try { - originalSourceLevel = new SpecificationVersion (initialSourceLevel); - } catch (NumberFormatException nfe) { - // If the javac.source has invalid value, do not preselect and log it. - LOGGER.log(Level.INFO, "Invalid javac.source: " + initialSourceLevel); - } - } - if (initialTargetLevel != null && initialTargetLevel.length() > 0) { - try { - SpecificationVersion originalTargetLevel = new SpecificationVersion (initialTargetLevel); - if (this.originalSourceLevel == null || this.originalSourceLevel.compareTo(originalTargetLevel)<0) { - this.originalSourceLevel = originalTargetLevel; - } - } catch (NumberFormatException nfe) { - //If the javac.target has invalid value, do not preselect and log it - LOGGER.warning("Invalid javac.target: "+initialTargetLevel); //NOI18N - } - } - this.selectedSourceLevel = this.originalSourceLevel; - } - - public SourceLevelComboBoxModel(ComboBoxModel platformComboBoxModel, String initialSourceLevel, String initialTargetLevel, String j2eePlatform) { - this(platformComboBoxModel, initialSourceLevel, initialTargetLevel); - this.j2eePlatform = j2eePlatform; - } - - public int getSize() { - SourceLevelKey[] sLevels = getSourceLevels(); - return sLevels.length; - } - - public Object getElementAt(int index) { - SourceLevelKey[] sLevels = getSourceLevels(); - assert index >=0 && index< sLevels.length; - return sLevels[index]; - } - - public Object getSelectedItem () { - SourceLevelKey[] keys = getSourceLevels(); - for (int i=0; i0 && - !shouldChangePlatform(selectedSourceLevel, version)) { - //Restore original - this.platformComboBoxModel.setSelectedItem(this.activePlatform); - return; - } - else { - this.originalSourceLevel = null; - } - } - this.activePlatform = selectedPlatform; - resetCache(); - } - - private void resetCache() { - synchronized (this) { - this.sourceLevelCache = null; - } - this.fireContentsChanged(this, -1, -1); - } - - private SourceLevelKey[] getSourceLevels() { - if (this.sourceLevelCache == null) { - PlatformKey selectedPlatform = (PlatformKey) this.platformComboBoxModel.getSelectedItem(); - JavaPlatform platform = getPlatform(selectedPlatform); - List sLevels = new ArrayList(); - //If platform == null broken platform, the source level range is unknown - //The source level combo box should be empty and disabled - boolean selSourceLevelValid = false; - if (platform != null) { - SpecificationVersion version = platform.getSpecification().getVersion(); - int index = INITIAL_VERSION_MINOR; - // #71619 - source level lower than 1.5 won't be shown for Java EE 5 project - if (j2eePlatform != null && j2eePlatform.equals(EjbJarProjectProperties.JAVA_EE_5)) { - index = INITIAL_VERSION_MINOR_JAVA_EE_5; - } - SpecificationVersion template = new SpecificationVersion (VERSION_PREFIX + Integer.toString (index++)); - boolean origSourceLevelValid = false; - - while (template.compareTo(version)<=0) { - if (template.equals(this.originalSourceLevel)) { - origSourceLevelValid = true; - } - if (template.equals(this.selectedSourceLevel)) { - selSourceLevelValid = true; - } - sLevels.add (new SourceLevelKey (template)); - template = new SpecificationVersion (VERSION_PREFIX + Integer.toString (index++)); - } - if (this.originalSourceLevel != null && !origSourceLevelValid) { - if (originalSourceLevel.equals(this.selectedSourceLevel)) { - selSourceLevelValid = true; - } - sLevels.add (new SourceLevelKey(this.originalSourceLevel,true)); - } - } - this.sourceLevelCache = sLevels.toArray(new SourceLevelKey[sLevels.size()]); - if (!selSourceLevelValid) { - this.selectedSourceLevel = this.sourceLevelCache.length == 0 ? - null : this.sourceLevelCache[this.sourceLevelCache.length-1].getSourceLevel(); - } - } - return this.sourceLevelCache; - } - - private static boolean shouldChangePlatform (SpecificationVersion selectedSourceLevel, SpecificationVersion platformSourceLevel) { - JButton changeOption = new JButton (NbBundle.getMessage(PlatformUiSupport.class, "CTL_ChangePlatform")); - changeOption.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PlatformUiSupport.class, "AD_ChangePlatform")); - String message = MessageFormat.format (NbBundle.getMessage(PlatformUiSupport.class,"TXT_ChangePlatform"),new Object[] { - selectedSourceLevel.toString(), - platformSourceLevel.toString(), - }); - return DialogDisplayer.getDefault().notify( - new NotifyDescriptor (message, - NbBundle.getMessage(PlatformUiSupport.class,"TXT_ChangePlatformTitle"), - NotifyDescriptor.DEFAULT_OPTION, - NotifyDescriptor.WARNING_MESSAGE, - new Object[] { - changeOption, - NotifyDescriptor.CANCEL_OPTION - }, - changeOption)) == changeOption; - } - } - - private static class SourceLevelListCellRenderer implements ListCellRenderer { - - ListCellRenderer delegate; - - public SourceLevelListCellRenderer() { - this.delegate = HtmlRenderer.createRenderer(); - } - - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - String message; - if (value == null) { - message = ""; //NOI18N - } - else { - assert value instanceof SourceLevelKey; - SourceLevelKey key = (SourceLevelKey) value; - if (key.isBroken()) { - message = "" + //NOI18N - NbBundle.getMessage(PlatformUiSupport.class,"TXT_InvalidSourceLevel",key.getDisplayName()); - } - else { - message = key.getDisplayName(); - } - } - return this.delegate.getListCellRendererComponent(list, message, index, isSelected, cellHasFocus); - } - } -} diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/logicalview/libraries/ActionFilterNode.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/logicalview/libraries/ActionFilterNode.java --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/logicalview/libraries/ActionFilterNode.java +++ b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/logicalview/libraries/ActionFilterNode.java @@ -66,9 +66,9 @@ import org.netbeans.spi.project.support. import org.netbeans.spi.project.support.ant.EditableProperties; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.ReferenceHelper; -import org.netbeans.modules.j2ee.ejbjarproject.UpdateHelper; import org.netbeans.modules.j2ee.ejbjarproject.classpath.ClassPathSupport; import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.openide.nodes.FilterNode.Children; import org.openide.util.Exceptions; diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/logicalview/libraries/LibrariesNode.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/logicalview/libraries/LibrariesNode.java --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/logicalview/libraries/LibrariesNode.java +++ b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/logicalview/libraries/LibrariesNode.java @@ -99,12 +99,12 @@ import org.netbeans.spi.project.support. import org.netbeans.spi.project.support.ant.ReferenceHelper; import org.netbeans.spi.java.project.support.ui.PackageView; import org.netbeans.modules.j2ee.ejbjarproject.ui.FoldersListSettings; -import org.netbeans.modules.j2ee.ejbjarproject.UpdateHelper; import org.netbeans.modules.j2ee.ejbjarproject.classpath.EjbJarProjectClassPathExtender; import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.AntArtifactChooser; import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarClassPathUi; import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.LibrariesChooser; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.spi.java.classpath.support.ClassPathSupport; import org.openide.util.Exceptions; import org.openide.util.lookup.Lookups; diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/logicalview/libraries/ProjectNode.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/logicalview/libraries/ProjectNode.java --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/logicalview/libraries/ProjectNode.java +++ b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/logicalview/libraries/ProjectNode.java @@ -78,7 +78,7 @@ import org.netbeans.spi.project.support. import org.netbeans.spi.project.support.ant.ReferenceHelper; import org.netbeans.modules.j2ee.ejbjarproject.classpath.ClassPathSupport; import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; -import org.netbeans.modules.j2ee.ejbjarproject.UpdateHelper; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.openide.filesystems.FileObject; import org.openide.util.Exceptions; import org.openide.util.Lookup; diff --git a/java.commonapi/build.xml b/java.commonapi/build.xml new file mode 100644 --- /dev/null +++ b/java.commonapi/build.xml @@ -0,0 +1,46 @@ + + + + + + diff --git a/java.commonapi/manifest.mf b/java.commonapi/manifest.mf new file mode 100644 --- /dev/null +++ b/java.commonapi/manifest.mf @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: org.netbeans.modules.java.api.common/0 +OpenIDE-Module-Layer: org/netbeans/modules/java/api/common/resources/layer.xml +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/api/common/resources/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff --git a/java.commonapi/nbproject/project.properties b/java.commonapi/nbproject/project.properties new file mode 100644 --- /dev/null +++ b/java.commonapi/nbproject/project.properties @@ -0,0 +1,3 @@ +is.autoload=true +javac.compilerargs=-Xlint -Xlint:-serial +javac.source=1.5 diff --git a/java.commonapi/nbproject/project.xml b/java.commonapi/nbproject/project.xml new file mode 100644 --- /dev/null +++ b/java.commonapi/nbproject/project.xml @@ -0,0 +1,152 @@ + + + org.netbeans.modules.apisupport.project + + + org.netbeans.modules.java.api.common + + + org.netbeans.api.java + + + + 1 + 1.14 + + + + org.netbeans.modules.java.platform + + + + 1 + 1.10 + + + + org.netbeans.modules.java.project + + + + 1 + 1.13 + + + + org.netbeans.modules.project.ant + + + + 1 + 1.18 + + + + org.netbeans.modules.project.libraries + + + + 1 + 1.16 + + + + org.netbeans.modules.projectapi + + + + 1 + 1.14 + + + + org.netbeans.modules.queries + + + + 1 + 1.11 + + + + org.openide.awt + + + + 6.12 + + + + org.openide.dialogs + + + + 7.6 + + + + org.openide.filesystems + + + + 7.4 + + + + org.openide.modules + + + + 7.4 + + + + org.openide.util + + + + 7.11 + + + + + + unit + + org.netbeans.modules.diff + + + org.netbeans.modules.masterfs + + + org.netbeans.modules.project.ant + + + + + org.netbeans.modules.projectapi + + + + + org.openide.util + + + + + + + org.netbeans.modules.j2ee.clientproject + org.netbeans.modules.j2ee.common + org.netbeans.modules.j2ee.earproject + org.netbeans.modules.j2ee.ejbjarproject + org.netbeans.modules.java.j2seproject + org.netbeans.modules.web.project + org.netbeans.modules.java.api.common + org.netbeans.modules.java.api.common.ant + org.netbeans.modules.java.api.common.queries + org.netbeans.modules.java.api.common.ui + + + + diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/Bundle.properties b/java.commonapi/src/org/netbeans/modules/java/api/common/Bundle.properties new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/Bundle.properties @@ -0,0 +1,39 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. +# +# The contents of this file are subject to the terms of either the GNU +# General Public License Version 2 only ("GPL") or the Common +# Development and Distribution License("CDDL") (collectively, the +# "License"). You may not use this file except in compliance with the +# License. You can obtain a copy of the License at +# http://www.netbeans.org/cddl-gplv2.html +# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the +# specific language governing permissions and limitations under the +# License. When distributing the software, include this License Header +# Notice in each file and include the License file at +# nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this +# particular file as subject to the "Classpath" exception as provided +# by Sun in the GPL Version 2 section of the License file that +# accompanied this code. If applicable, add the following below the +# License Header, with the fields enclosed by brackets [] replaced by +# your own identifying information: +# "Portions Copyrighted [year] [name of copyright owner]" +# +# If you wish your version of this file to be governed by only the CDDL +# or only the GPL Version 2, indicate your decision by adding +# "[Contributor] elects to include this software in this distribution +# under the [CDDL or GPL Version 2] license." If you do not indicate a +# single choice of license, a recipient has the option to distribute +# your version of this file under either the CDDL, the GPL Version 2 or +# to extend the choice of license to its licensees as provided above. +# However, if you add GPL Version 2 code and therefore, elected the GPL +# Version 2 license, then the option applies only if the new code is +# made subject to such option by the copyright holder. +# +# Contributor(s): +# +# Portions Copyrighted 2008 Sun Microsystems, Inc. + +NAME_src.dir=Source Packages +NAME_test.src.dir=Test Packages diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/SourceRoots.java b/java.commonapi/src/org/netbeans/modules/java/api/common/SourceRoots.java new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/SourceRoots.java @@ -0,0 +1,144 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2007 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.java.api.common; + +import java.beans.PropertyChangeListener; +import java.io.File; +import java.net.URL; +import org.openide.filesystems.FileObject; +import org.openide.util.NbBundle; + +/** + * Represents a project source roots. It can be used to obtain source roots as Ant properties, {@link FileObject}'s + * or {@link URL}s. + * All implementations have to be thread safe and have to listen to the changes + * in Ant project metadata (see {@link #PROP_ROOT_PROPERTIES}) as well as + * in project properties (see {@link #PROP_ROOTS}). + * @author Tomas Zezula, Tomas Mysik + */ +public interface SourceRoots { + + /** + * Property name of a event that has to be fired when Ant project metadata change. + */ + String PROP_ROOT_PROPERTIES = SourceRoots.class.getName() + ".rootProperties"; //NOI18N + /** + * Property name of a event that has to be fired when project properties change. + */ + String PROP_ROOTS = SourceRoots.class.getName() + ".roots"; //NOI18N + + /** + * Default label for sources node used in {@link org.netbeans.spi.project.ui.LogicalViewProvider}. + */ + String DEFAULT_SOURCE_LABEL = NbBundle.getMessage(SourceRoots.class, "NAME_src.dir"); + /** + * Default label for tests node used in {@link org.netbeans.spi.project.ui.LogicalViewProvider}. + */ + String DEFAULT_TEST_LABEL = NbBundle.getMessage(SourceRoots.class, "NAME_test.src.dir"); + + /** + * Returns the display names of source roots. + * The returned array has the same length as an array returned by the {@link #getRootProperties()}. + * It may contain empty {@link String}s but not null. + * @return an array of source roots names. + */ + String[] getRootNames(); + + /** + * Returns names of Ant properties in the project.properties file holding the source roots. + * @return an array of String. + */ + String[] getRootProperties(); + + /** + * Returns the source roots in the form of absolute paths. + * @return an array of {@link FileObject}s. + */ + FileObject[] getRoots(); + + /** + * Returns the source roots as {@link URL}s. + * @return an array of {@link URL}. + */ + URL[] getRootURLs(); + + /** + * Adds {@link PropertyChangeListener}, see class description for more information + * about listening to the source roots changes. + * @param listener a listener to add. + */ + void addPropertyChangeListener(PropertyChangeListener listener); + + /** + * Removes {@link PropertyChangeListener}, see class description for more information + * about listening to the source roots changes. + * @param listener a listener to remove. + */ + void removePropertyChangeListener(PropertyChangeListener listener); + + /** + * Replaces the current roots by the given ones. + * @param roots the {@link URL}s of the new roots. + * @param labels the names of the new roots. + */ + void putRoots(final URL[] roots, final String[] labels); + + /** + * Translates root name into display name of source/test root. + * @param rootName the name of root got from {@link SourceRoots#getRootNames()}. + * @param propName the name of a property the root is stored in. + * @return the label to be displayed. + */ + String getRootDisplayName(String rootName, String propName); + + /** + * Creates initial display name of source/test root. + * @param sourceRoot the source root. + * @return the label to be displayed. + */ + String createInitialDisplayName(File sourceRoot); + + /** + * Returns true if the current {@link SourceRoots} instance represents source roots belonging to + * the test compilation unit. + * @return boolean true if the instance belongs to the test compilation unit, false otherwise. + */ + boolean isTest(); +} diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/SourceRootsImpl.java b/java.commonapi/src/org/netbeans/modules/java/api/common/SourceRootsImpl.java new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/SourceRootsImpl.java @@ -0,0 +1,427 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ + +package org.netbeans.modules.java.api.common; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URI; +import java.util.Arrays; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.HashMap; +import java.text.MessageFormat; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; +import org.openide.util.WeakListeners; +import org.openide.util.Mutex; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.w3c.dom.Document; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.AntProjectEvent; +import org.netbeans.spi.project.support.ant.AntProjectListener; +import org.netbeans.spi.project.support.ant.EditableProperties; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.netbeans.spi.project.support.ant.ReferenceHelper; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.api.java.project.JavaProjectConstants; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; + +/** + * This class represents a project source roots. It is used to obtain roots as Ant properties, FileObject's + * or URLs. + * @author Tomas Zezula + */ +final class SourceRootsImpl implements SourceRoots { + + private final UpdateHelper helper; + private final PropertyEvaluator evaluator; + private final ReferenceHelper refHelper; + private final String projectConfigurationNamespace; + private final String elementName; + private final String newRootNameTemplate; + private List sourceRootProperties; + private List sourceRootNames; + private List sourceRoots; + private List sourceRootURLs; + private final PropertyChangeSupport support; + private final ProjectMetadataListener listener; + private final boolean isTest; + private final File projectDir; + + public SourceRootsImpl(UpdateHelper helper, PropertyEvaluator evaluator, ReferenceHelper refHelper, + String projectConfigurationNamespace, String elementName, boolean isTest, String newRootNameTemplate) { + assert helper != null; + assert evaluator != null; + assert refHelper != null; + assert projectConfigurationNamespace != null; + assert elementName != null; + assert newRootNameTemplate != null; + + this.helper = helper; + this.evaluator = evaluator; + this.refHelper = refHelper; + this.projectConfigurationNamespace = projectConfigurationNamespace; + this.elementName = elementName; + this.isTest = isTest; + this.newRootNameTemplate = newRootNameTemplate; + this.projectDir = FileUtil.toFile(this.helper.getAntProjectHelper().getProjectDirectory()); + this.support = new PropertyChangeSupport(this); + this.listener = new ProjectMetadataListener(); + this.evaluator.addPropertyChangeListener(WeakListeners.propertyChange(this.listener, this.evaluator)); + this.helper.getAntProjectHelper().addAntProjectListener( + WeakListeners.create(AntProjectListener.class, this.listener, this.helper)); + } + + + public String[] getRootNames() { + return ProjectManager.mutex().readAccess(new Mutex.Action() { + public String[] run() { + synchronized (SourceRootsImpl.this) { + if (sourceRootNames == null) { + readProjectMetadata(); + } + } + return sourceRootNames.toArray(new String[sourceRootNames.size()]); + } + }); + } + + public String[] getRootProperties() { + return ProjectManager.mutex().readAccess(new Mutex.Action() { + public String[] run() { + synchronized (SourceRootsImpl.this) { + if (sourceRootProperties == null) { + readProjectMetadata(); + } + return sourceRootProperties.toArray(new String[sourceRootProperties.size()]); + } + } + }); + } + + public FileObject[] getRoots() { + return ProjectManager.mutex().readAccess(new Mutex.Action() { + public FileObject[] run() { + synchronized (this) { + // local caching + if (sourceRoots == null) { + String[] srcProps = getRootProperties(); + List result = new ArrayList(); + for (String p : srcProps) { + String prop = evaluator.getProperty(p); + if (prop != null) { + FileObject f = helper.getAntProjectHelper().resolveFileObject(prop); + if (f == null) { + continue; + } + if (FileUtil.isArchiveFile(f)) { + f = FileUtil.getArchiveRoot(f); + } + result.add(f); + } + } + sourceRoots = Collections.unmodifiableList(result); + } + } + return sourceRoots.toArray(new FileObject[sourceRoots.size()]); + } + }); + } + + public URL[] getRootURLs() { + return ProjectManager.mutex().readAccess(new Mutex.Action() { + public URL[] run() { + synchronized (this) { + // local caching + if (sourceRootURLs == null) { + List result = new ArrayList(); + for (String srcProp : getRootProperties()) { + String prop = evaluator.getProperty(srcProp); + if (prop != null) { + File f = helper.getAntProjectHelper().resolveFile(prop); + try { + URL url = f.toURI().toURL(); + if (!f.exists()) { + url = new URL(url.toExternalForm() + "/"); // NOI18N + } else if (f.isFile()) { + // file cannot be a source root (archives are not supported as source roots). + continue; + } + assert url.toExternalForm().endsWith("/") : "#90639 violation for " + url + "; " + + f + " exists? " + f.exists() + " dir? " + f.isDirectory() + + " file? " + f.isFile(); + result.add(url); + } catch (MalformedURLException e) { + Exceptions.printStackTrace(e); + } + } + } + sourceRootURLs = Collections.unmodifiableList(result); + } + } + return sourceRootURLs.toArray(new URL[sourceRootURLs.size()]); + } + }); + } + + private Map getRootsToProps() { + return ProjectManager.mutex().readAccess(new Mutex.Action>() { + public Map run() { + Map result = new HashMap(); + for (String srcProp : getRootProperties()) { + String prop = evaluator.getProperty(srcProp); + if (prop != null) { + File f = helper.getAntProjectHelper().resolveFile(prop); + try { + URL url = f.toURI().toURL(); + if (!f.exists()) { + url = new URL(url.toExternalForm() + "/"); // NOI18N + } else if (f.isFile()) { + // file cannot be a source root (archives are not supported as source roots). + continue; + } + assert url.toExternalForm().endsWith("/") : "#90639 violation for " + url + "; " + + f + " exists? " + f.exists() + " dir? " + f.isDirectory() + + " file? " + f.isFile(); + result.put(url, srcProp); + } catch (MalformedURLException e) { + Exceptions.printStackTrace(e); + } + } + } + return result; + } + }); + } + + public void addPropertyChangeListener(PropertyChangeListener listener) { + support.addPropertyChangeListener(listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + support.removePropertyChangeListener(listener); + } + + + public void putRoots(final URL[] roots, final String[] labels) { + ProjectManager.mutex().writeAccess( + new Runnable() { + public void run() { + Map oldRoots2props = getRootsToProps(); + Map newRoots2lab = new HashMap(); + for (int i = 0; i < roots.length; i++) { + newRoots2lab.put(roots[i], labels[i]); + } + Element cfgEl = helper.getPrimaryConfigurationData(true); + NodeList nl = cfgEl.getElementsByTagNameNS(projectConfigurationNamespace, elementName); + assert nl.getLength() == 1 : "Illegal project.xml"; //NOI18N + Element ownerElement = (Element) nl.item(0); + // remove all old roots + NodeList rootsNodes = + ownerElement.getElementsByTagNameNS(projectConfigurationNamespace, "root"); //NOI18N + while (rootsNodes.getLength() > 0) { + Element root = (Element) rootsNodes.item(0); + ownerElement.removeChild(root); + } + // remove all unused root properties + List newRoots = Arrays.asList(roots); + Map propsToRemove = new HashMap(oldRoots2props); + propsToRemove.keySet().removeAll(newRoots); + EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + props.keySet().removeAll(propsToRemove.values()); + helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); + // add the new roots + Document doc = ownerElement.getOwnerDocument(); + oldRoots2props.keySet().retainAll(newRoots); + for (URL newRoot : newRoots) { + String rootName = oldRoots2props.get(newRoot); + if (rootName == null) { + // root is new generate property for it + props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + String[] names = newRoot.getPath().split("/"); //NOI18N + rootName = MessageFormat.format( + newRootNameTemplate, new Object[] {names[names.length - 1], ""}); // NOI18N + int rootIndex = 1; + while (props.containsKey(rootName)) { + rootIndex++; + rootName = MessageFormat.format( + newRootNameTemplate, new Object[] {names[names.length - 1], rootIndex}); + } + File f = FileUtil.normalizeFile(new File(URI.create(newRoot.toExternalForm()))); + File projDir = FileUtil.toFile(helper.getAntProjectHelper().getProjectDirectory()); + String path = f.getAbsolutePath(); + String prjPath = projDir.getAbsolutePath() + File.separatorChar; + if (path.startsWith(prjPath)) { + path = path.substring(prjPath.length()); + } else { + path = refHelper.createForeignFileReference( + f, JavaProjectConstants.SOURCES_TYPE_JAVA); + props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + } + props.put(rootName, path); + helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); + } + Element newRootNode = doc.createElementNS(projectConfigurationNamespace, "root"); //NOI18N + newRootNode.setAttribute("id", rootName); //NOI18N + String label = newRoots2lab.get(newRoot); + if (label != null + && label.length() > 0 + && !label.equals(getRootDisplayName(null, rootName))) { //NOI18N + newRootNode.setAttribute("name", label); //NOI18N + } + ownerElement.appendChild(newRootNode); + } + helper.putPrimaryConfigurationData(cfgEl, true); + } + } + ); + } + + public String getRootDisplayName(String rootName, String propName) { + if (rootName == null || rootName.length() == 0) { + // if the prop is src.dir use the default name + if (isTest && "test.src.dir".equals(propName)) { //NOI18N + rootName = DEFAULT_TEST_LABEL; + } else if (!isTest && "src.dir".equals(propName)) { //NOI18N + rootName = DEFAULT_SOURCE_LABEL; + } else { + // if the name is not given, it should be either a relative path in the project dir + // or absolute path when the root is not under the project dir + String propValue = evaluator.getProperty(propName); + File sourceRoot = propValue == null ? null : helper.getAntProjectHelper().resolveFile(propValue); + rootName = createInitialDisplayName(sourceRoot); + } + } + return rootName; + } + + public String createInitialDisplayName(File sourceRoot) { + String rootName; + if (sourceRoot != null) { + String srPath = sourceRoot.getAbsolutePath(); + String pdPath = projectDir.getAbsolutePath() + File.separatorChar; + if (srPath.startsWith(pdPath)) { + rootName = srPath.substring(pdPath.length()); + } else { + rootName = sourceRoot.getAbsolutePath(); + } + } else { + rootName = isTest ? DEFAULT_TEST_LABEL : DEFAULT_SOURCE_LABEL; + } + return rootName; + } + + public boolean isTest() { + return isTest; + } + + private void resetCache(boolean isXMLChange, String propName) { + boolean fire = false; + synchronized (this) { + // in case of change reset local cache + if (isXMLChange) { + sourceRootProperties = null; + sourceRootNames = null; + sourceRoots = null; + sourceRootURLs = null; + fire = true; + } else if (propName == null || (sourceRootProperties != null && sourceRootProperties.contains(propName))) { + sourceRoots = null; + sourceRootURLs = null; + fire = true; + } + } + if (fire) { + if (isXMLChange) { + support.firePropertyChange(PROP_ROOT_PROPERTIES, null, null); + } + support.firePropertyChange(PROP_ROOTS, null, null); + } + } + + private void readProjectMetadata() { + Element cfgEl = helper.getPrimaryConfigurationData(true); + NodeList nl = cfgEl.getElementsByTagNameNS(projectConfigurationNamespace, elementName); + assert nl.getLength() == 0 || nl.getLength() == 1 : "Illegal project.xml"; //NOI18N + List rootProps = new ArrayList(); + List rootNames = new ArrayList(); + // it can be 0 in the case when the project is created by J2SEProjectGenerator and not yet customized + if (nl.getLength() == 1) { + NodeList roots = + ((Element) nl.item(0)).getElementsByTagNameNS(projectConfigurationNamespace, "root"); //NOI18N + for (int i = 0; i < roots.getLength(); i++) { + Element root = (Element) roots.item(i); + String value = root.getAttribute("id"); //NOI18N + assert value.length() > 0 : "Illegal project.xml"; + rootProps.add(value); + value = root.getAttribute("name"); //NOI18N + rootNames.add(value); + } + } + sourceRootProperties = Collections.unmodifiableList(rootProps); + sourceRootNames = Collections.unmodifiableList(rootNames); + } + + private class ProjectMetadataListener implements PropertyChangeListener, AntProjectListener { + + public void propertyChange(PropertyChangeEvent evt) { + resetCache(false, evt.getPropertyName()); + } + + public void configurationXmlChanged(AntProjectEvent ev) { + resetCache(true, null); + } + + public void propertiesChanged(AntProjectEvent ev) { + // handled by propertyChange + } + } + +} diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/SourceRootsSupport.java b/java.commonapi/src/org/netbeans/modules/java/api/common/SourceRootsSupport.java new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/SourceRootsSupport.java @@ -0,0 +1,68 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2007 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.java.api.common; + +import org.netbeans.modules.java.api.common.ant.UpdateHelper; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.netbeans.spi.project.support.ant.ReferenceHelper; +import org.openide.util.Parameters; + +/** + * Support class for creating {@link SourceRoots} implementation. + * @author Tomas Mysik + */ +public final class SourceRootsSupport { + + private SourceRootsSupport() { + } + + public static SourceRoots create(UpdateHelper helper, PropertyEvaluator evaluator, ReferenceHelper refHelper, + String projectConfigurationNamespace, String elementName, boolean isTest, String newRootNameTemplate) { + Parameters.notNull("helper", helper); // NOI18N + Parameters.notNull("evaluator", evaluator); // NOI18N + Parameters.notNull("refHelper", refHelper); // NOI18N + Parameters.notNull("projectConfigurationNamespace", projectConfigurationNamespace); // NOI18N + Parameters.notNull("elementName", elementName); // NOI18N + Parameters.notNull("newRootNameTemplate", newRootNameTemplate); // NOI18N + + return new SourceRootsImpl(helper, evaluator, refHelper, projectConfigurationNamespace, elementName, isTest, + newRootNameTemplate); + } +} diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/ant/UpdateHelper.java b/java.commonapi/src/org/netbeans/modules/java/api/common/ant/UpdateHelper.java new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/ant/UpdateHelper.java @@ -0,0 +1,217 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ + +package org.netbeans.modules.java.api.common.ant; + +import java.io.IOException; +import org.openide.util.Exceptions; +import org.w3c.dom.Element; +import org.openide.util.Mutex; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.EditableProperties; +import org.openide.util.MutexException; +import org.openide.util.Parameters; + + +/** + * Proxy for the {@link AntProjectHelper} which defers the update of the project metadata + * to explicit user action. Caller has to provide implementation of {@link UpdateProject} + * which takes care of updating project itself. + * @author Tomas Zezula, Tomas Mysik + * @see UpdateImplementation + */ +public final class UpdateHelper { + + private final UpdateImplementation updateProject; + private final AntProjectHelper helper; + + /** + * Create new {@link UpdateHelper}. + * @param updateProject {@link UpdateImplementation} which takes care of updating project itself. + * @param helper {@link AntProjectHelper} to be proxied. + */ + public UpdateHelper(UpdateImplementation updateProject, AntProjectHelper helper) { + Parameters.notNull("updateProject", updateProject); // NOI18N + Parameters.notNull("helper", helper); // NOI18N + + this.updateProject = updateProject; + this.helper = helper; + } + + /** + * In the case that the project is of current version or the properties + * are not {@link AntProjectHelper#PROJECT_PROPERTIES_PATH} it calls + * {@link AntProjectHelper#getProperties(String)} otherwise it asks for updated project properties. + * @param path a relative URI in the project directory. + * @return a set of properties. + */ + public EditableProperties getProperties(final String path) { + return ProjectManager.mutex().readAccess(new Mutex.Action() { + public EditableProperties run() { + if (!isCurrent() && AntProjectHelper.PROJECT_PROPERTIES_PATH.equals(path)) { + // only project properties were changed + return updateProject.getUpdatedProjectProperties(); + } + return helper.getProperties(path); + } + }); + } + + /** + * In the case that the project is of current version or the properties + * are not {@link AntProjectHelper#PROJECT_PROPERTIES_PATH} it calls + * {@link AntProjectHelper#putProperties(String, EditableProperties)} otherwise it asks to update project. + * If the project can be updated, it does the update and calls + * {@link AntProjectHelper#putProperties(String, EditableProperties)}. + * @param path a relative URI in the project directory. + * @param props a set of properties. + */ + public void putProperties(final String path, final EditableProperties props) { + ProjectManager.mutex().writeAccess( + new Runnable() { + public void run() { + if (isCurrent() || !AntProjectHelper.PROJECT_PROPERTIES_PATH.equals(path)) { + // only project props should cause update + helper.putProperties(path, props); + } else if (updateProject.canUpdate()) { + try { + updateProject.saveUpdate(props); + helper.putProperties(path, props); + } catch (IOException ioe) { + Exceptions.printStackTrace(ioe); + } + } + } + }); + } + + /** + * In the case that the project is of current version or shared is false it delegates to + * {@link AntProjectHelper#getPrimaryConfigurationData(boolean)}. + * Otherwise it creates an in memory update of shared configuration data and returns it. + * @param shared if true, refers to project.xml, else refers to + * private.xml. + * @return the configuration data that is available. + */ + public Element getPrimaryConfigurationData(final boolean shared) { + return ProjectManager.mutex().readAccess(new Mutex.Action() { + public Element run() { + if (!shared || isCurrent()) { // only shared props should cause update + return helper.getPrimaryConfigurationData(shared); + } + return updateProject.getUpdatedSharedConfigurationData(); + } + }); + } + + /** + * In the case that the project is of current version or shared is false it calls + * {@link AntProjectHelper#putPrimaryConfigurationData(Element, boolean)}. + * Otherwise the project can be updated, it does the update and calls + * {@link AntProjectHelper#putPrimaryConfigurationData(Element, boolean)}. + * @param element the configuration data + * @param shared if true, refers to project.xml, else refers to + * private.xml + */ + public void putPrimaryConfigurationData(final Element element, final boolean shared) { + ProjectManager.mutex().writeAccess(new Runnable() { + public void run () { + if (!shared || isCurrent()) { + helper.putPrimaryConfigurationData(element, shared); + } else if (updateProject.canUpdate()) { + try { + updateProject.saveUpdate(null); + helper.putPrimaryConfigurationData(element, shared); + } catch (IOException ioe) { + Exceptions.printStackTrace(ioe); + } + } + } + }); + } + + /** + * Request saving of update. If the project is not of current version and the project can be updated, then + * the update is done. + * @return true if the metadata are of current version or updated. + * @throws IOException if error occurs during saving. + */ + public boolean requestUpdate() throws IOException { + try { + return ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() { + public Boolean run() throws IOException { + if (isCurrent()) { + return true; + } + if (!updateProject.canUpdate()) { + return false; + } + updateProject.saveUpdate(null); + return true; + } + }); + + } catch (MutexException ex) { + Exception inner = ex.getException(); + if (inner instanceof IOException) { + throw (IOException) inner; + } + throw (RuntimeException) inner; + } + } + + /** + * Return true if the project is of current version. + * @return true if the project is of current version. + */ + public boolean isCurrent() { + return updateProject.isCurrent(); + } + + /** + * Get the {@link AntProjectHelper} that is proxied. + * @return the {@link AntProjectHelper} that is proxied. + */ + public AntProjectHelper getAntProjectHelper() { + return helper; + } +} diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/ant/UpdateImplementation.java b/java.commonapi/src/org/netbeans/modules/java/api/common/ant/UpdateImplementation.java new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/ant/UpdateImplementation.java @@ -0,0 +1,87 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2007 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.java.api.common.ant; + +import java.io.IOException; +import org.netbeans.spi.project.support.ant.EditableProperties; +import org.w3c.dom.Element; + +/** + * Interface that has to be implemented in order to use {@link UpdateHelper}. It represents and does the project update + * process itself. + * @author Tomas Mysik + * @see UpdateHelper + */ +public interface UpdateImplementation { + + /** + * Return true if the project is of current version. + * @return true if the project is of current version. + */ + boolean isCurrent(); + + /** + * Return true if the project can be updated. + * @return true if the project can be updated. + */ + boolean canUpdate(); + + /** + * Saving of update. If the project is of current version it should probably do nothing. + * @param props project properties to be saved, can be null. There's no need to save them because + * {@link UpdateHelper} does it. + * @throws IOException if error occurs during saving. + */ + void saveUpdate(final EditableProperties props) throws IOException; + + /** + * Creates probably an in memory update of shared configuration data and return it. + * @return the configuration data that is available. + * @see {@link UpdateHelper#getPrimaryConfigurationData(boolean)} + */ + Element getUpdatedSharedConfigurationData(); + + /** + * Creates probably an in memory update of project properties. + * @return a set of properties. + * @see {@link UpdateHelper#getProperties(String)} + */ + EditableProperties getUpdatedProjectProperties(); +} diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/queries/CompiledSourceForBinaryQueryImpl.java b/java.commonapi/src/org/netbeans/modules/java/api/common/queries/CompiledSourceForBinaryQueryImpl.java new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/queries/CompiledSourceForBinaryQueryImpl.java @@ -0,0 +1,160 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.modules.java.api.common.queries; + +import org.netbeans.modules.java.api.common.SourceRoots; +import java.io.File; +import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import java.net.URL; +import java.net.MalformedURLException; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeEvent; +import java.util.Map; +import java.util.HashMap; +import javax.swing.event.ChangeListener; +import org.netbeans.api.java.queries.SourceForBinaryQuery; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.openide.util.ChangeSupport; +import org.openide.util.Exceptions; + +/** + * Default implementation of {@link SourceForBinaryQueryImplementation}. + * @author Jesse Glick, Tomas Zezula + */ +class CompiledSourceForBinaryQueryImpl implements SourceForBinaryQueryImplementation { + + private final AntProjectHelper helper; + private final PropertyEvaluator evaluator; + private final SourceRoots sourceRoots; + private final SourceRoots testRoots; + private final Map cache = new HashMap(); + + public CompiledSourceForBinaryQueryImpl(AntProjectHelper helper, PropertyEvaluator evaluator, SourceRoots srcRoots, + SourceRoots testRoots) { + assert helper != null; + assert evaluator != null; + assert srcRoots != null; + assert testRoots != null; + + this.helper = helper; + this.evaluator = evaluator; + this.sourceRoots = srcRoots; + this.testRoots = testRoots; + } + + public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) { + if (FileUtil.getArchiveFile(binaryRoot) != null) { + binaryRoot = FileUtil.getArchiveFile(binaryRoot); + // XXX check whether this is really the root + } + SourceForBinaryQuery.Result res = cache.get(binaryRoot); + if (res != null) { + return res; + } + SourceRoots src = null; + if (hasSources(binaryRoot, "build.classes.dir")) { //NOI18N + src = sourceRoots; + } else if (hasSources(binaryRoot, "dist.jar")) { //NOI18N + src = sourceRoots; + } else if (hasSources(binaryRoot, "build.test.classes.dir")) { //NOI18N + src = testRoots; + } + if (src == null) { + return null; + } + res = new Result(src); + cache.put(binaryRoot, res); + return res; + } + + private boolean hasSources(URL binaryRoot, String binaryProperty) { + try { + String outDir = evaluator.getProperty(binaryProperty); + if (outDir != null) { + File f = helper.resolveFile(outDir); + URL url = f.toURI().toURL(); + if (!f.exists() && !f.getPath().toLowerCase().endsWith(".jar")) { // NOI18N + // non-existing + assert !url.toExternalForm().endsWith("/") : f; // NOI18N + url = new URL(url.toExternalForm() + "/"); // NOI18N + } + if (url.equals(binaryRoot)) { + return true; + } + } + } catch (MalformedURLException malformedURL) { + Exceptions.printStackTrace(malformedURL); + } + return false; + } + + private class Result implements SourceForBinaryQuery.Result, PropertyChangeListener { + + private final ChangeSupport changeSupport = new ChangeSupport(this); + private SourceRoots sourceRoots; + + public Result(SourceRoots sourceRoots) { + this.sourceRoots = sourceRoots; + this.sourceRoots.addPropertyChangeListener(this); + } + + public FileObject[] getRoots() { + return this.sourceRoots.getRoots(); // no need to cache it, SourceRoots does + } + + public void addChangeListener (ChangeListener l) { + changeSupport.addChangeListener(l); + } + + public void removeChangeListener (ChangeListener l) { + changeSupport.removeChangeListener(l); + } + + public void propertyChange(PropertyChangeEvent evt) { + if (SourceRoots.PROP_ROOTS.equals(evt.getPropertyName())) { + changeSupport.fireChange(); + } + } + } +} diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/queries/FileBuiltQueryImpl.java b/java.commonapi/src/org/netbeans/modules/java/api/common/queries/FileBuiltQueryImpl.java new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/queries/FileBuiltQueryImpl.java @@ -0,0 +1,122 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.modules.java.api.common.queries; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import org.netbeans.api.project.ProjectManager; +import org.openide.filesystems.FileObject; +import org.netbeans.api.queries.FileBuiltQuery; +import org.netbeans.modules.java.api.common.SourceRoots; +import org.netbeans.spi.queries.FileBuiltQueryImplementation; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.openide.util.Mutex.Action; + + +/** + * Default implementation of {@link FileBuiltQueryImplementation}. + * @author Jesse Glick, Tomas Zezula + */ +final class FileBuiltQueryImpl implements FileBuiltQueryImplementation, PropertyChangeListener { + + private FileBuiltQueryImplementation delegate; + private final AntProjectHelper helper; + private final PropertyEvaluator evaluator; + private final SourceRoots sourceRoots; + private final SourceRoots testRoots; + + FileBuiltQueryImpl(AntProjectHelper helper, PropertyEvaluator evaluator, SourceRoots sourceRoots, + SourceRoots testRoots) { + assert helper != null; + assert evaluator != null; + assert sourceRoots != null; + assert testRoots != null; + + this.helper = helper; + this.evaluator = evaluator; + this.sourceRoots = sourceRoots; + this.testRoots = testRoots; + this.sourceRoots.addPropertyChangeListener(this); + this.testRoots.addPropertyChangeListener(this); + } + + public FileBuiltQuery.Status getStatus(final FileObject file) { + return ProjectManager.mutex().readAccess(new Action() { + public FileBuiltQuery.Status run() { + return getStatusImpl(file); + } + }); + } + + private synchronized FileBuiltQuery.Status getStatusImpl(FileObject file) { + if (delegate == null) { + delegate = createDelegate(); + } + return delegate.getStatus(file); + } + + + private FileBuiltQueryImplementation createDelegate() { + String[] srcRoots = sourceRoots.getRootProperties(); + String[] tstRoots = testRoots.getRootProperties(); + String[] from = new String [srcRoots.length + tstRoots.length]; + String[] to = new String [srcRoots.length + tstRoots.length]; + for (int i = 0; i < srcRoots.length; i++) { + from[i] = "${" + srcRoots[i] + "}/*.java"; // NOI18N + to[i] = "${build.classes.dir}/*.class"; // NOI18N + } + for (int i = 0; i < tstRoots.length; i++) { + from[srcRoots.length + i] = "${" + tstRoots[i] + "}/*.java"; // NOI18N + to[srcRoots.length + i] = "${build.test.classes.dir}/*.class"; // NOI18N + } + return helper.createGlobFileBuiltQuery(evaluator, from, to); // save to pass APH + } + + public void propertyChange(PropertyChangeEvent evt) { + if (SourceRoots.PROP_ROOT_PROPERTIES.equals(evt.getPropertyName())) { + synchronized (this) { + delegate = null; + // XXX: what to do with already returned Statuses + } + } + } +} diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/queries/FileEncodingQueryImpl.java b/java.commonapi/src/org/netbeans/modules/java/api/common/queries/FileEncodingQueryImpl.java new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/queries/FileEncodingQueryImpl.java @@ -0,0 +1,109 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ + +package org.netbeans.modules.java.api.common.queries; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.nio.charset.Charset; +import java.nio.charset.IllegalCharsetNameException; +import java.nio.charset.UnsupportedCharsetException; +import org.netbeans.spi.queries.FileEncodingQueryImplementation; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.openide.filesystems.FileObject; +import org.openide.util.Parameters; + +/** + * Default implementation of {@link FileEncodingQueryImplementation}. It listens to the changes + * in particular property values. + * @author Tomas Zezula + */ +class FileEncodingQueryImpl extends FileEncodingQueryImplementation implements PropertyChangeListener { + + private final PropertyEvaluator eval; + private final String sourceEncodingPropertyName; + private Charset cache; + + public FileEncodingQueryImpl(final PropertyEvaluator eval, final String sourceEncodingPropertyName) { + assert eval != null; + assert sourceEncodingPropertyName != null; + + this.eval = eval; + this.sourceEncodingPropertyName = sourceEncodingPropertyName; + this.eval.addPropertyChangeListener(this); + } + + public Charset getEncoding(FileObject file) { + Parameters.notNull("file", file); // NOI18N + + synchronized (this) { + if (cache != null) { + return cache; + } + } + String enc = eval.getProperty(sourceEncodingPropertyName); + synchronized (this) { + if (cache == null) { + try { + //From discussion with K. Frank the project returns Charset.defaultCharset () + //for old j2se projects. The old project used system encoding => Charset.defaultCharset () + //should work for most users. + cache = enc == null ? Charset.defaultCharset() : Charset.forName(enc); + } catch (IllegalCharsetNameException exception) { + return null; + } catch (UnsupportedCharsetException exception) { + return null; + } + } + return cache; + } + } + + public void propertyChange(PropertyChangeEvent event) { + String propName = event.getPropertyName(); + if (propName == null || propName.equals(sourceEncodingPropertyName)) { + synchronized (this) { + cache = null; + } + } + } + +} diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/queries/JavadocForBinaryQueryImpl.java b/java.commonapi/src/org/netbeans/modules/java/api/common/queries/JavadocForBinaryQueryImpl.java new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/queries/JavadocForBinaryQueryImpl.java @@ -0,0 +1,173 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.modules.java.api.common.queries; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.File; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.openide.filesystems.FileUtil; +import java.net.URL; +import java.net.MalformedURLException; +import javax.swing.event.ChangeListener; +import org.netbeans.api.java.queries.JavadocForBinaryQuery; +import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.openide.util.ChangeSupport; +import org.openide.util.Exceptions; +import org.openide.util.WeakListeners; + +/** + * Finds Javadoc (if it is built) corresponding to binaries in a project. + * @author David Konecny, Jesse Glick + */ +class JavadocForBinaryQueryImpl implements JavadocForBinaryQueryImplementation { + + private static final String PROP_JAVADOC_DIR = "dist.javadoc.dir"; //NOI18N + + private final AntProjectHelper helper; + private final PropertyEvaluator evaluator; + + public JavadocForBinaryQueryImpl(AntProjectHelper helper, PropertyEvaluator evaluator) { + assert helper != null; + assert evaluator != null; + + this.helper = helper; + this.evaluator = evaluator; + } + + public JavadocForBinaryQuery.Result findJavadoc(final URL binaryRoot) { + + class Result implements JavadocForBinaryQuery.Result, PropertyChangeListener { + + private final ChangeSupport changeSupport = new ChangeSupport(this); + private URL[] result; + private long eventId; + + public Result() { + JavadocForBinaryQueryImpl.this.evaluator.addPropertyChangeListener( + WeakListeners.propertyChange(this, JavadocForBinaryQueryImpl.this.evaluator)); + } + + public URL[] getRoots() { + long lEventId; + synchronized (this) { + if (this.result != null) { + return this.result; + } + lEventId = eventId; + } + URL[] lResult; + String javadocDir = evaluator.getProperty(PROP_JAVADOC_DIR); + if (javadocDir != null) { + File f = helper.resolveFile(javadocDir); + try { + URL url = f.toURI().toURL(); + if (!f.exists()) { + assert !url.toExternalForm().endsWith("/") : f; // NOI18N + url = new URL(url.toExternalForm() + "/"); // NOI18N + } + lResult = new URL[] {url}; + } catch (MalformedURLException e) { + lResult = new URL[0]; + Exceptions.printStackTrace(e); + } + } else { + lResult = new URL[0]; + } + synchronized (this) { + if (lEventId == eventId) { + if (this.result == null) { + this.result = lResult; + } + return this.result; + } + return lResult; + } + } + + public void addChangeListener(final ChangeListener l) { + changeSupport.addChangeListener(l); + } + + public void removeChangeListener(final ChangeListener l) { + changeSupport.removeChangeListener(l); + } + + public void propertyChange(final PropertyChangeEvent event) { + if (PROP_JAVADOC_DIR.equals(event.getPropertyName())) { + synchronized (this) { + result = null; + eventId++; + } + this.changeSupport.fireChange(); + } + } + } + if (isRootOwner(binaryRoot, "build.classes.dir") || isRootOwner(binaryRoot, "dist.jar")) { //NOI18N + return new Result(); + } + return null; + } + + private boolean isRootOwner(URL binaryRoot, String binaryProperty) { + try { + if (FileUtil.getArchiveFile(binaryRoot) != null) { + binaryRoot = FileUtil.getArchiveFile(binaryRoot); + // XXX check whether this is really the root + } + String outDir = evaluator.getProperty(binaryProperty); + if (outDir != null) { + File f = helper.resolveFile(outDir); + URL url = f.toURI().toURL(); + if (!f.exists() && !f.getPath().toLowerCase().endsWith(".jar")) { // NOI18N + assert !url.toExternalForm().endsWith("/") : f; // NOI18N + url = new URL(url.toExternalForm() + "/"); // NOI18N + } + return url.equals(binaryRoot) + || binaryRoot.toExternalForm().startsWith(url.toExternalForm()); + } + } catch (MalformedURLException malformedURL) { + Exceptions.printStackTrace(malformedURL); + } + return false; + } +} diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/queries/QuerySupport.java b/java.commonapi/src/org/netbeans/modules/java/api/common/queries/QuerySupport.java new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/queries/QuerySupport.java @@ -0,0 +1,190 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2007 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.java.api.common.queries; + +import org.netbeans.modules.java.api.common.SourceRoots; +import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation; +import org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation; +import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation; +import org.netbeans.spi.java.queries.SourceLevelQueryImplementation; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.netbeans.spi.queries.FileBuiltQueryImplementation; +import org.netbeans.spi.queries.FileEncodingQueryImplementation; +import org.netbeans.spi.queries.SharabilityQueryImplementation; +import org.openide.util.Parameters; + +/** + * Support class for creating different types of queries implementations. + * @author Tomas Mysik + */ +public final class QuerySupport { + + private QuerySupport() { + } + + /** + * Create a new query to provide information about where Java sources + * corresponding to binaries (classfiles) can be found. + * @param helper {@link AntProjectHelper} used for resolving files, e.g. output directory. + * @param evaluator {@link PropertyEvaluator} used for obtaining project properties. + * @param srcRoots a list of source roots. + * @param testRoots a list of test roots. + * @return {@link SourceForBinaryQueryImplementation} to provide information about where Java sources can be found. + * @see SourceForBinaryQueryImplementation + */ + public static SourceForBinaryQueryImplementation createCompiledSourceForBinaryQuery(AntProjectHelper helper, + PropertyEvaluator evaluator, SourceRoots srcRoots, SourceRoots testRoots) { + Parameters.notNull("helper", helper); // NOI18N + Parameters.notNull("evaluator", evaluator); // NOI18N + Parameters.notNull("srcRoots", srcRoots); // NOI18N + Parameters.notNull("testRoots", testRoots); // NOI18N + + return new CompiledSourceForBinaryQueryImpl(helper, evaluator, srcRoots, testRoots); + } + + /** + * Create a new query to provide information about encoding of a file. The returned query listens to the changes + * in particular property values. + * @param eval {@link PropertyEvaluator} used for obtaining the value of source encoding. + * @param sourceEncodingPropertyName the source encoding property name. + * @return a {@link FileEncodingQueryImplementation} to provide information about encoding of a file. + */ + public static FileEncodingQueryImplementation createFileEncodingQuery(PropertyEvaluator eval, + String sourceEncodingPropertyName) { + Parameters.notNull("eval", eval); // NOI18N + Parameters.notNull("sourceEncodingPropertyName", sourceEncodingPropertyName); // NOI18N + + return new FileEncodingQueryImpl(eval, sourceEncodingPropertyName); + } + + /** + * Create a new query to find Javadoc. The returned query listens on changes of the Javadoc directory. + * @param helper {@link AntProjectHelper} used for resolving files, e.g. output directory. + * @param evaluator {@link PropertyEvaluator} used for obtaining the Javadoc root. + * @return a {@link JavadocForBinaryQueryImplementation} to find Javadoc. + */ + public static JavadocForBinaryQueryImplementation createJavadocForBinaryQuery(AntProjectHelper helper, + PropertyEvaluator evaluator) { + Parameters.notNull("helper", helper); // NOI18N + Parameters.notNull("evaluator", evaluator); // NOI18N + + return new JavadocForBinaryQueryImpl(helper, evaluator); + } + + /** + * Create a new query to provide information about files sharability. The returned query listens to the changes + * in particular source roots. + * @param helper {@link AntProjectHelper} used for creating a query itself. + * @param evaluator a {@link PropertyEvaluator property evaluator} to interpret paths with. + * @param srcRoots a list of source roots to treat as sharable. + * @param testRoots a list of test roots to treat as sharable. + * @param additionalSourceRoots additional paths to treat as sharable (just pure property names, do not + * use ${ and } characters). Can be null. + * @return a {@link SharabilityQueryImplementation} to provide information about files sharability. + */ + public static SharabilityQueryImplementation createSharabilityQuery(AntProjectHelper helper, + PropertyEvaluator evaluator, SourceRoots srcRoots, SourceRoots testRoots, + String... additionalSourceRoots) { + Parameters.notNull("helper", helper); // NOI18N + Parameters.notNull("evaluator", evaluator); // NOI18N + Parameters.notNull("srcRoots", srcRoots); // NOI18N + Parameters.notNull("testRoots", testRoots); // NOI18N + + return new SharabilityQueryImpl(helper, evaluator, srcRoots, testRoots, additionalSourceRoots); + } + + /** + * Create a new query to provide information about files sharability without any additional source roots. See + * {@link #createSharabilityQuery(AntProjectHelper, PropertyEvaluator, SourceRoots, SourceRoots, String...) + * createSharabilityQuery()} + * for more information. + */ + public static SharabilityQueryImplementation createSharabilityQuery(AntProjectHelper helper, + PropertyEvaluator evaluator, SourceRoots srcRoots, SourceRoots testRoots) { + + return createSharabilityQuery(helper, evaluator, srcRoots, testRoots, (String[]) null); + } + + /** + * Create a new query to find out specification source level of Java source files. + * @param evaluator {@link PropertyEvaluator} used for obtaining needed properties. + * @return a {@link SourceLevelQueryImplementation} to find out specification source level of Java source files. + */ + public static SourceLevelQueryImplementation createSourceLevelQuery(PropertyEvaluator evaluator) { + Parameters.notNull("evaluator", evaluator); // NOI18N + + return new SourceLevelQueryImpl(evaluator); + } + + /** + * Create a new query to find Java package roots of unit tests for Java package root of sources and vice versa. + * @param sourceRoots a list of source roots. + * @param testRoots a list of test roots. + * @return a {@link MultipleRootsUnitTestForSourceQueryImplementation} to find Java package roots of unit tests + * for Java package root of sources and vice versa. + */ + public static MultipleRootsUnitTestForSourceQueryImplementation createUnitTestForSourceQuery( + SourceRoots sourceRoots, SourceRoots testRoots) { + Parameters.notNull("sourceRoots", sourceRoots); // NOI18N + Parameters.notNull("testRoots", testRoots); // NOI18N + + return new UnitTestForSourceQueryImpl(sourceRoots, testRoots); + } + + /** + * Create a new query to test whether a file can be considered to be built (up to date). The returned query + * listens to the changes in particular source roots. + * @param helper {@link AntProjectHelper} used for creating a query itself. + * @param evaluator {@link PropertyEvaluator} used for obtaining needed properties. + * @param sourceRoots a list of source roots. + * @param testRoots a list of test roots. + * @return a {@link FileBuiltQueryImplementation} to test whether a file can be considered to be built (up to date). + */ + public static FileBuiltQueryImplementation createFileBuiltQuery(AntProjectHelper helper, + PropertyEvaluator evaluator, SourceRoots sourceRoots, SourceRoots testRoots) { + Parameters.notNull("helper", helper); // NOI18N + Parameters.notNull("evaluator", evaluator); // NOI18N + Parameters.notNull("sourceRoots", sourceRoots); // NOI18N + Parameters.notNull("testRoots", testRoots); // NOI18N + + return new FileBuiltQueryImpl(helper, evaluator, sourceRoots, testRoots); + } +} diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/queries/SharabilityQueryImpl.java b/java.commonapi/src/org/netbeans/modules/java/api/common/queries/SharabilityQueryImpl.java new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/queries/SharabilityQueryImpl.java @@ -0,0 +1,133 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ + +package org.netbeans.modules.java.api.common.queries; + +import org.netbeans.modules.java.api.common.SourceRoots; +import java.io.File; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.openide.util.Mutex; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.spi.queries.SharabilityQueryImplementation; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; + +/** + * Default implementation of {@link SharabilityQueryImplementation} which is capable to take more sources. + * It listens to the changes in particular property values. + * @author Tomas Zezula, Tomas Mysik + */ +class SharabilityQueryImpl implements SharabilityQueryImplementation, PropertyChangeListener { + + private final AntProjectHelper helper; + private final PropertyEvaluator evaluator; + private final SourceRoots srcRoots; + private final SourceRoots testRoots; + private final List additionalSourceRoots; + private SharabilityQueryImplementation delegate; + + public SharabilityQueryImpl(AntProjectHelper helper, PropertyEvaluator evaluator, SourceRoots srcRoots, + SourceRoots testRoots, String... additionalSourceRoots) { + assert helper != null; + assert evaluator != null; + assert srcRoots != null; + assert testRoots != null; + + this.helper = helper; + this.evaluator = evaluator; + this.srcRoots = srcRoots; + this.testRoots = testRoots; + if (additionalSourceRoots != null) { + this.additionalSourceRoots = Collections.unmodifiableList(Arrays.asList(additionalSourceRoots)); + } else { + this.additionalSourceRoots = Collections.emptyList(); + } + this.srcRoots.addPropertyChangeListener(this); + this.testRoots.addPropertyChangeListener(this); + } + + public int getSharability(final File file) { + return ProjectManager.mutex().readAccess(new Mutex.Action() { + public Integer run() { + synchronized (SharabilityQueryImpl.this) { + if (delegate == null) { + delegate = createDelegate(); + } + return delegate.getSharability(file); + } + } + }); + } + + public void propertyChange(PropertyChangeEvent evt) { + if (SourceRoots.PROP_ROOT_PROPERTIES.equals(evt.getPropertyName())) { + synchronized (this) { + delegate = null; + } + } + } + + private SharabilityQueryImplementation createDelegate() { + String[] srcProps = srcRoots.getRootProperties(); + String[] testProps = testRoots.getRootProperties(); + String[] buildDirectories = new String[] {"${dist.dir}", "${build.dir}"}; // NOI18N + + int size = srcProps.length; + size += testProps.length; + size += additionalSourceRoots.size(); + List props = new ArrayList(size); + + for (String src : srcProps) { + props.add("${" + src + "}"); // NOI18N + } + for (String test : testProps) { + props.add("${" + test + "}"); // NOI18N + } + props.addAll(additionalSourceRoots); + + return helper.createSharabilityQuery(evaluator, props.toArray(new String[props.size()]), buildDirectories); + } +} diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/queries/SourceLevelQueryImpl.java b/java.commonapi/src/org/netbeans/modules/java/api/common/queries/SourceLevelQueryImpl.java new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/queries/SourceLevelQueryImpl.java @@ -0,0 +1,85 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.modules.java.api.common.queries; + +import org.netbeans.api.java.platform.JavaPlatform; +import org.netbeans.api.java.platform.JavaPlatformManager; +import org.netbeans.api.java.platform.Specification; +import org.netbeans.modules.java.api.common.util.CommonProjectUtils; +import org.netbeans.spi.java.queries.SourceLevelQueryImplementation; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.netbeans.spi.project.support.ant.PropertyUtils; +import org.netbeans.spi.project.support.ant.EditableProperties; +import org.openide.filesystems.FileObject; + +/** + * Returns source level of project Java source files. + * @author David Konecny + */ +class SourceLevelQueryImpl implements SourceLevelQueryImplementation { + + private final PropertyEvaluator evaluator; + + public SourceLevelQueryImpl(PropertyEvaluator evaluator) { + assert evaluator != null; + + this.evaluator = evaluator; + } + + public String getSourceLevel(FileObject javaFile) { + final String activePlatform = evaluator.getProperty("platform.active"); //NOI18N + if (CommonProjectUtils.getActivePlatform(activePlatform) != null) { + String sl = evaluator.getProperty("javac.source"); //NOI18N + if (sl != null && sl.length() > 0) { + return sl; + } + return null; + } + + EditableProperties props = PropertyUtils.getGlobalProperties(); + String sl = props.get("default.javac.source"); //NOI18N + if (sl != null && sl.length() > 0) { + return sl; + } + return null; + } + +} diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/queries/UnitTestForSourceQueryImpl.java b/java.commonapi/src/org/netbeans/modules/java/api/common/queries/UnitTestForSourceQueryImpl.java new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/queries/UnitTestForSourceQueryImpl.java @@ -0,0 +1,89 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ + +package org.netbeans.modules.java.api.common.queries; + +import org.netbeans.modules.java.api.common.SourceRoots; +import java.net.URL; +import org.netbeans.api.project.FileOwnerQuery; +import org.netbeans.api.project.Project; +import org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation; +import org.openide.filesystems.FileObject; + +/** + * Default implementation of {@link MultipleRootsUnitTestForSourceQueryImplementation}. + * @author Tomas Zezula + */ +class UnitTestForSourceQueryImpl implements MultipleRootsUnitTestForSourceQueryImplementation { + + private final SourceRoots sourceRoots; + private final SourceRoots testRoots; + + public UnitTestForSourceQueryImpl(SourceRoots sourceRoots, SourceRoots testRoots) { + assert sourceRoots != null; + assert testRoots != null; + + this.sourceRoots = sourceRoots; + this.testRoots = testRoots; + } + + public URL[] findUnitTests(FileObject source) { + return find(source, sourceRoots, testRoots); + } + + public URL[] findSources(FileObject unitTest) { + return find(unitTest, testRoots, sourceRoots); + } + + private URL[] find(FileObject file, SourceRoots from, SourceRoots to) { + Project p = FileOwnerQuery.getOwner(file); + if (p == null) { + return null; + } + for (FileObject fromRoot : from.getRoots()) { + if (fromRoot.equals(file)) { + return to.getRootURLs(); + } + } + return null; + } + +} diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/resources/Bundle.properties b/java.commonapi/src/org/netbeans/modules/java/api/common/resources/Bundle.properties new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/resources/Bundle.properties @@ -0,0 +1,6 @@ +OpenIDE-Module-Display-Category=Java +OpenIDE-Module-Long-Description=\ + Miscellaneous API implementations that are common for all the project types, it means J2SEProject, Java EE projects such as WebProject, EjbJarProject, AppClientProject. \ + Supplies default implementation of FileEncodingQuery, SourceLevelQuery etc. +OpenIDE-Module-Name=Java Common Project API +OpenIDE-Module-Short-Description=API implementations common to all the project types. diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/resources/layer.xml b/java.commonapi/src/org/netbeans/modules/java/api/common/resources/layer.xml new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/resources/layer.xml @@ -0,0 +1,4 @@ + + + + diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/ui/Bundle.properties b/java.commonapi/src/org/netbeans/modules/java/api/common/ui/Bundle.properties new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/ui/Bundle.properties @@ -0,0 +1,53 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. +# +# The contents of this file are subject to the terms of either the GNU +# General Public License Version 2 only ("GPL") or the Common +# Development and Distribution License("CDDL") (collectively, the +# "License"). You may not use this file except in compliance with the +# License. You can obtain a copy of the License at +# http://www.netbeans.org/cddl-gplv2.html +# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the +# specific language governing permissions and limitations under the +# License. When distributing the software, include this License Header +# Notice in each file and include the License file at +# nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this +# particular file as subject to the "Classpath" exception as provided +# by Sun in the GPL Version 2 section of the License file that +# accompanied this code. If applicable, add the following below the +# License Header, with the fields enclosed by brackets [] replaced by +# your own identifying information: +# "Portions Copyrighted [year] [name of copyright owner]" +# +# If you wish your version of this file to be governed by only the CDDL +# or only the GPL Version 2, indicate your decision by adding +# "[Contributor] elects to include this software in this distribution +# under the [CDDL or GPL Version 2] license." If you do not indicate a +# single choice of license, a recipient has the option to distribute +# your version of this file under either the CDDL, the GPL Version 2 or +# to extend the choice of license to its licensees as provided above. +# However, if you add GPL Version 2 code and therefore, elected the GPL +# Version 2 license, then the option applies only if the new code is +# made subject to such option by the copyright holder. +# +# Contributor(s): +# +# Portions Copyrighted 2007 Sun Microsystems, Inc. + +# PlatformUiSupport +# {0} - JDK version +LBL_JDK=JDK {0} +# {0} - Platform Name +TXT_BrokenPlatformFmt=Missing platform: {0} +# {0} - Source Level +TXT_InvalidSourceLevel=Illegal Source Level: {0} +CTL_ChangePlatform=Change Platform +AD_ChangePlatform=N/A +TXT_ChangePlatform=Incompatible Source Level Value {0}\n\ + The source level version for this project ({0}) is higher than the\n\ + Java Platform version you just selected ({1}). Changing the Java\n\ + Platform will update the project''s source level to version {1}.\n\n\ + Do you want to change the Java Platform and update the source level\n\ + version? +TXT_ChangePlatformTitle=Change Java Platform diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/ui/PlatformUiSupport.java b/java.commonapi/src/org/netbeans/modules/java/api/common/ui/PlatformUiSupport.java new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/ui/PlatformUiSupport.java @@ -0,0 +1,778 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ + +package org.netbeans.modules.java.api.common.ui; + +import java.awt.Component; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; +import java.util.logging.Logger; +import javax.swing.AbstractListModel; +import javax.swing.ComboBoxModel; +import javax.swing.JButton; +import javax.swing.JList; +import javax.swing.ListCellRenderer; +import javax.swing.event.ListDataEvent; +import javax.swing.event.ListDataListener; +import org.netbeans.api.java.platform.JavaPlatform; +import org.netbeans.api.java.platform.JavaPlatformManager; +import org.netbeans.api.java.platform.Specification; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; +import org.netbeans.spi.project.support.ant.EditableProperties; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.awt.HtmlRenderer; +import org.openide.modules.SpecificationVersion; +import org.openide.util.NbBundle; +import org.openide.util.Parameters; +import org.openide.util.WeakListeners; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * Support class for {@link JavaPlatform} manipulation in project customizer. + * @author Tomas Zezula, Tomas Mysik + */ +public final class PlatformUiSupport { + + /** + * Enum used for specifying minimal version of the source level. Currently, only JDK 5 is supported. + * @see PlatformUiSupport#createSourceLevelComboBoxModel(ComboBoxModel, String, String, String) + */ + public enum JDK { VERSION_5 } + + private static final SpecificationVersion JDK_1_5 = new SpecificationVersion("1.5"); //NOI18N + private static final SpecificationVersion JDK_1_6 = new SpecificationVersion("1.6"); //NOI18N + private static final Logger LOGGER = Logger.getLogger(PlatformUiSupport.class.getName()); + + private PlatformUiSupport() { + } + + /** + * Create a {@link ComboBoxModel} of Java platforms. + * The model listens on the {@link JavaPlatformManager} and update its + * state according to the changes. + * @param activePlatform the active project's platform, can be null. + * @return {@link ComboBoxModel}. + */ + public static ComboBoxModel createPlatformComboBoxModel(String activePlatform) { + return new PlatformComboBoxModel(activePlatform); + } + + + /** + * Create a {@link ListCellRenderer} for rendering items of the {@link ComboBoxModel} + * created by the {@link PlatformUiSupport#createPlatformComboBoxModel(String)} method. + * @return {@link ListCellRenderer}. + */ + public static ListCellRenderer createPlatformListCellRenderer() { + return new PlatformListCellRenderer(); + } + + /** + * Like {@link #storePlatform(EditableProperties, UpdateHelper, Object, Object)}, but platform name may be + * null (in such case the default platform is used). + * @param props project's shared properties. + * @param helper {@link UpdateHelper} that is capable to upgrade project metadata if needed. + * @param projectConfigurationNamespace project configuration namespace. + * @param platformName platform name to store, can be null. + * @param sourceLevel specification version to store. + */ + public static void storePlatform(EditableProperties props, UpdateHelper helper, + String projectConfigurationNamespace, String platformName, SpecificationVersion sourceLevel) { + Parameters.notNull("props", props); //NOI18N + Parameters.notNull("helper", helper); //NOI18N + Parameters.notNull("projectConfigurationNamespace", projectConfigurationNamespace); //NOI18N + Parameters.notNull("sourceLevel", sourceLevel); //NOI18N + + PlatformKey platformKey; + if (platformName != null) { + platformKey = new PlatformKey(PlatformUiSupport.findPlatform(platformName)); + } else { + platformKey = new PlatformKey(JavaPlatformManager.getDefault().getDefaultPlatform()); + } + storePlatform(props, helper, projectConfigurationNamespace, platformKey, new SourceLevelKey(sourceLevel)); + } + + /** + * Stores active platform, javac.source and javac.target into the project's metadata. + * @param props project's shared properties + * @param helper {@link UpdateHelper} that is capable to upgrade project metadata if needed. + * @param projectConfigurationNamespace project configuration namespace. + * @param platformKey the {@link PlatformKey} got from the platform model. + * @param sourceLevelKey {@link SourceLevelKey} representing source level; can be null. + */ + public static void storePlatform(EditableProperties props, UpdateHelper helper, + String projectConfigurationNamespace, Object platformKey, Object sourceLevelKey) { + Parameters.notNull("props", props); //NOI18N + Parameters.notNull("helper", helper); //NOI18N + Parameters.notNull("projectConfigurationNamespace", projectConfigurationNamespace); //NOI18N + Parameters.notNull("platformKey", platformKey); //NOI18N + + assert platformKey instanceof PlatformKey; + + final String javaPlatformKey = "platform.active"; //NOI18N + final String javacSourceKey = "javac.source"; //NOI18N + final String javacTargetKey = "javac.target"; //NOI18N + + PlatformKey pk = (PlatformKey) platformKey; + JavaPlatform platform = getPlatform(pk); + // null means active broken (unresolved) platform, no need to do anything + if (platform == null) { + return; + } + + SpecificationVersion jdk13 = new SpecificationVersion("1.3"); //NOI18N + String platformAntName = platform.getProperties().get("platform.ant.name"); //NOI18N + assert platformAntName != null; + props.put(javaPlatformKey, platformAntName); + Element root = helper.getPrimaryConfigurationData(true); + boolean changed = false; + NodeList explicitPlatformNodes = + root.getElementsByTagNameNS(projectConfigurationNamespace, "explicit-platform"); //NOI18N + + if (pk.isDefaultPlatform()) { + if (explicitPlatformNodes.getLength() == 1) { + root.removeChild(explicitPlatformNodes.item(0)); + changed = true; + } + } else { + Element explicitPlatform; + switch (explicitPlatformNodes.getLength()) { + case 0: + explicitPlatform = root.getOwnerDocument().createElementNS( + projectConfigurationNamespace, "explicit-platform"); //NOI18N + NodeList sourceRootNodes = root.getElementsByTagNameNS( + projectConfigurationNamespace, "source-roots"); //NOI18N + assert sourceRootNodes.getLength() == 1 : "Broken project.xml file"; + + root.insertBefore(explicitPlatform, sourceRootNodes.item(0)); + changed = true; + break; + case 1: + explicitPlatform = (Element) explicitPlatformNodes.item(0); + break; + default: + throw new AssertionError("Broken project.xml file"); + } + String explicitSourceAttrValue = explicitPlatform.getAttribute("explicit-source-supported"); //NOI18N + if (jdk13.compareTo(platform.getSpecification().getVersion()) >= 0 + && !"false".equals(explicitSourceAttrValue)) { //NOI18N + explicitPlatform.setAttribute("explicit-source-supported", "false"); //NOI18N + changed = true; + } else if (jdk13.compareTo(platform.getSpecification().getVersion()) < 0 + && !"true".equals(explicitSourceAttrValue)) { //NOI18N + explicitPlatform.setAttribute("explicit-source-supported", "true"); //NOI18N + changed = true; + } + } + + SpecificationVersion sourceLevel; + if (sourceLevelKey == null) { + sourceLevel = platform.getSpecification().getVersion(); + } else { + assert sourceLevelKey instanceof SourceLevelKey; + sourceLevel = ((SourceLevelKey) sourceLevelKey).getSourceLevel(); + } + String javacSource = sourceLevel.toString(); + String javacTarget = javacSource; + + //Issue #116490 + // Customizer value | -source | -target + // JDK 1.2 1.2 1.1 + // JDK 1.3 1.3 1.1 + // JDK 1.4 1.4 1.4 + // JDK 5 1.5 1.5 + // JDK 6 1.5 1.6 + // JDK 7 1.7 1.7 - should bring a new language features + if (jdk13.compareTo(sourceLevel) >= 0) { + javacTarget = "1.1"; //NOI18N + } else if (JDK_1_6.equals(sourceLevel)) { + javacSource = JDK_1_5.toString(); + } + + if (!javacSource.equals(props.getProperty(javacSourceKey))) { + props.setProperty(javacSourceKey, javacSource); + } + if (!javacTarget.equals(props.getProperty(javacTargetKey))) { + props.setProperty(javacTargetKey, javacTarget); + } + + if (changed) { + helper.putPrimaryConfigurationData(root, true); + } + } + + + /** + * Return a {@link JavaPlatform} for an item obtained from the ComboBoxModel created by + * the {@link PlatformUiSupport#createPlatformComboBoxModel(String)} method. This method + * can return null if the platform is broken. + * @param platformKey an item obtained from {@link ComboBoxModel} created by + * {@link PlatformUiSupport#createPlatformComboBoxModel(String)}. + * @return {@link JavaPlatform} or null in case when platform is broken. + * @throws IllegalArgumentException if the input parameter is not an object created by platform combobox model. + */ + public static JavaPlatform getPlatform(Object platformKey) { + Parameters.notNull("platformKey", platformKey); //NOI18N + + if (platformKey instanceof PlatformKey) { + return getPlatform((PlatformKey) platformKey); + } + throw new IllegalArgumentException(); + } + + /** + * Create {@link ComboBoxModel} of source levels for active platform. + * The model listens on the platform's {@link ComboBoxModel} and update its + * state according to the changes. It is possible to define minimal JDK version. + * @param platformComboBoxModel the platform's model used for listenning. + * @param initialSourceLevel initial source level value. + * @param initialTargetLevel initial target level value. + * @param minimalJDKVersion minimal JDK version to be displayed. It can be null if all the JDK versions + * should be displayed (typically for Java SE project). + * @return {@link ComboBoxModel} of {@link SourceLevelKey}. + * @see #createSourceLevelComboBoxModel(ComboBoxModel, String, String) + */ + public static ComboBoxModel createSourceLevelComboBoxModel(ComboBoxModel platformComboBoxModel, + String initialSourceLevel, String initialTargetLevel, JDK minimalJDKVersion) { + Parameters.notNull("platformComboBoxModel", platformComboBoxModel); // NOI18N + Parameters.notNull("initialSourceLevel", initialSourceLevel); // NOI18N + Parameters.notNull("initialTargetLevel", initialTargetLevel); // NOI18N + + return new SourceLevelComboBoxModel(platformComboBoxModel, initialSourceLevel, initialTargetLevel, + minimalJDKVersion); + } + + /** + * Exactly like {@link #createSourceLevelComboBoxModel(ComboBoxModel, String, String, JDK)} + * but without any minimal JDK version. + * @param platformComboBoxModel the platform's model used for listenning. + * @param initialSourceLevel initial source level value. + * @param initialTargetLevel initial target level value. + * @return {@link ComboBoxModel} of {@link SourceLevelKey}. + * @see #createSourceLevelComboBoxModel(ComboBoxModel, String, String, JDK) + */ + public static ComboBoxModel createSourceLevelComboBoxModel(ComboBoxModel platformComboBoxModel, + String initialSourceLevel, String initialTargetLevel) { + Parameters.notNull("platformComboBoxModel", platformComboBoxModel); // NOI18N + Parameters.notNull("initialSourceLevel", initialSourceLevel); // NOI18N + Parameters.notNull("initialTargetLevel", initialTargetLevel); // NOI18N + + return new SourceLevelComboBoxModel(platformComboBoxModel, initialSourceLevel, initialTargetLevel, null); + } + + /** + * Create {@link ListCellRenderer} for source levels. This method could be used when highlighting + * of illegal source levels is needed. + * @return {@link ListCellRenderer} for source levels. + */ + public static ListCellRenderer createSourceLevelListCellRenderer() { + return new SourceLevelListCellRenderer(); + } + + /** + * This class represents a JavaPlatform in the {@link ListModel} + * created by the {@link PlatformUiSupport#createPlatformComboBoxModel(String)} method. + */ + private static final class PlatformKey implements Comparable { + + private String name; + private JavaPlatform platform; + + /** + * Create a PlatformKey for a broken platform. + * @param name the ant name of the broken platform. + */ + public PlatformKey(String name) { + assert name != null; + this.name = name; + } + + /** + * Create a PlatformKey for a platform. + * @param platform the {@link JavaPlatform}. + */ + public PlatformKey(JavaPlatform platform) { + assert platform != null; + this.platform = platform; + } + + public int compareTo(Object o) { + return this.getDisplayName().compareTo(((PlatformKey) o).getDisplayName()); + } + + @Override + public boolean equals(Object other) { + if (other instanceof PlatformKey) { + PlatformKey otherKey = (PlatformKey) other; + boolean equals; + if (this.platform == null) { + equals = otherKey.platform == null; + } else { + equals = this.platform.equals(otherKey.platform); + } + return equals && otherKey.getDisplayName().equals(this.getDisplayName()); + } + return false; + } + + @Override + public int hashCode() { + return getDisplayName().hashCode(); + } + + @Override + public String toString() { + return getDisplayName(); + } + + public synchronized String getDisplayName() { + if (this.name == null) { + this.name = this.platform.getDisplayName(); + } + return this.name; + } + + public boolean isDefaultPlatform() { + if (this.platform == null) { + return false; + } + return this.platform.equals(JavaPlatformManager.getDefault().getDefaultPlatform()); + } + + public boolean isBroken() { + return this.platform == null; + } + } + + private static final class SourceLevelKey implements Comparable { + + private final SpecificationVersion sourceLevel; + private final boolean broken; + + public SourceLevelKey(final SpecificationVersion sourceLevel) { + this(sourceLevel, false); + } + + public SourceLevelKey(final SpecificationVersion sourceLevel, final boolean broken) { + assert sourceLevel != null : "Source level cannot be null"; + this.sourceLevel = sourceLevel; + this.broken = broken; + } + + public SpecificationVersion getSourceLevel() { + return this.sourceLevel; + } + + public boolean isBroken() { + return this.broken; + } + + public int compareTo(final Object other) { + assert other instanceof SourceLevelKey : "Illegal argument of SourceLevelKey.compareTo()"; + SourceLevelKey otherKey = (SourceLevelKey) other; + return this.sourceLevel.compareTo(otherKey.sourceLevel); + } + + @Override + public boolean equals(final Object other) { + return (other instanceof SourceLevelKey) + && ((SourceLevelKey) other).sourceLevel.equals(this.sourceLevel); + } + + @Override + public int hashCode() { + return this.sourceLevel.hashCode(); + } + + @Override + public String toString() { + StringBuilder buffer = new StringBuilder(); + if (this.broken) { + buffer.append("Broken: "); //NOI18N + } + buffer.append(this.sourceLevel.toString()); + return buffer.toString(); + } + + public String getDisplayName() { + String tmp = sourceLevel.toString(); + if (JDK_1_5.compareTo(sourceLevel) <= 0) { + tmp = tmp.replaceFirst("^1\\.([5-9]|\\d\\d+)$", "$1"); //NOI18N + } + return NbBundle.getMessage(PlatformUiSupport.class, "LBL_JDK", tmp); + } + } + + private static final class PlatformComboBoxModel extends AbstractListModel + implements ComboBoxModel, PropertyChangeListener { + private static final long serialVersionUID = 1L; + + private final JavaPlatformManager pm; + private PlatformKey[] platformNamesCache; + private String initialPlatform; + private PlatformKey selectedPlatform; + + public PlatformComboBoxModel(String initialPlatform) { + this.pm = JavaPlatformManager.getDefault(); + this.pm.addPropertyChangeListener(WeakListeners.propertyChange(this, this.pm)); + this.initialPlatform = initialPlatform; + } + + public int getSize() { + PlatformKey[] platformNames = getPlatformNames(); + return platformNames.length; + } + + public Object getElementAt(int index) { + PlatformKey[] platformNames = getPlatformNames(); + assert index >= 0 && index < platformNames.length; + return platformNames[index]; + } + + public Object getSelectedItem() { + getPlatformNames(); // force setting of selectedPlatform if it is not already done + return selectedPlatform; + } + + public void setSelectedItem(Object obj) { + selectedPlatform = (PlatformKey) obj; + fireContentsChanged(this, -1, -1); + } + + public void propertyChange(PropertyChangeEvent event) { + if (JavaPlatformManager.PROP_INSTALLED_PLATFORMS.equals(event.getPropertyName())) { + synchronized (this) { + platformNamesCache = null; + } + fireContentsChanged(this, -1, -1); + } + } + + private synchronized PlatformKey[] getPlatformNames() { + if (platformNamesCache == null) { + JavaPlatform[] platforms = pm.getPlatforms(null, new Specification("j2se", null)); //NOI18N + Set orderedNames = new TreeSet(); + boolean activeFound = false; + for (JavaPlatform platform : platforms) { + if (platform.getInstallFolders().size() > 0) { + PlatformKey pk = new PlatformKey(platform); + orderedNames.add(pk); + if (!activeFound && initialPlatform != null) { + String antName = platform.getProperties().get("platform.ant.name"); //NOI18N + if (initialPlatform.equals(antName)) { + if (selectedPlatform == null) { + selectedPlatform = pk; + initialPlatform = null; + } + activeFound = true; + } + } + } + } + if (!activeFound) { + if (initialPlatform == null) { + if (selectedPlatform == null || !orderedNames.contains(selectedPlatform)) { + selectedPlatform = new PlatformKey(JavaPlatformManager.getDefault().getDefaultPlatform()); + } + } else { + PlatformKey pk = new PlatformKey(initialPlatform); + orderedNames.add(pk); + if (selectedPlatform == null) { + selectedPlatform = pk; + } + } + } + platformNamesCache = orderedNames.toArray(new PlatformKey[0]); + } + return platformNamesCache; + } + + } + + private static final class PlatformListCellRenderer implements ListCellRenderer { + + private final ListCellRenderer delegate; + + public PlatformListCellRenderer() { + delegate = HtmlRenderer.createRenderer(); + } + + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, + boolean cellHasFocus) { + String name; + if (value == null) { + name = ""; //NOI18N + } else { + assert value instanceof PlatformKey : "Wrong model"; + PlatformKey key = (PlatformKey) value; + if (key.isBroken()) { + name = "" //NOI18N + + NbBundle.getMessage( + PlatformUiSupport.class, "TXT_BrokenPlatformFmt", key.getDisplayName()); + } else { + name = key.getDisplayName(); + } + } + return delegate.getListCellRendererComponent(list, name, index, isSelected, cellHasFocus); + } + } + + private static final class SourceLevelComboBoxModel extends AbstractListModel + implements ComboBoxModel, ListDataListener { + private static final long serialVersionUID = 1L; + + private static final String VERSION_PREFIX = "1."; // the version prefix // NOI18N + private static final int INITIAL_VERSION_MINOR = 2; // 1.2 + // if project is JAVA EE 5 show only 1.5 and higher + private static final int INITIAL_VERSION_MINOR_JAVA_EE_5 = 5; // 1.5 + + private final ComboBoxModel platformComboBoxModel; + private final JDK minimalJDKVersion; + private SpecificationVersion selectedSourceLevel; + private SpecificationVersion originalSourceLevel; + private SourceLevelKey[] sourceLevelCache; + private PlatformKey activePlatform; + + public SourceLevelComboBoxModel(ComboBoxModel platformComboBoxModel, String initialSourceLevel, + String initialTargetLevel, JDK minimalJDKVersion) { + this.platformComboBoxModel = platformComboBoxModel; + activePlatform = (PlatformKey) this.platformComboBoxModel.getSelectedItem(); + this.platformComboBoxModel.addListDataListener(this); + if (initialSourceLevel != null && initialSourceLevel.length() > 0) { + try { + originalSourceLevel = new SpecificationVersion(initialSourceLevel); + } catch (NumberFormatException nfe) { + // if the javac.source has invalid value, do not preselect and log it. + LOGGER.warning("Invalid javac.source: " + initialSourceLevel); + } + } + if (initialTargetLevel != null && initialTargetLevel.length() > 0) { + try { + SpecificationVersion originalTargetLevel = new SpecificationVersion(initialTargetLevel); + if (originalSourceLevel == null || originalSourceLevel.compareTo(originalTargetLevel)<0) { + originalSourceLevel = originalTargetLevel; + } + } catch (NumberFormatException nfe) { + // if the javac.target has invalid value, do not preselect and log it + LOGGER.warning("Invalid javac.target: "+initialTargetLevel); + } + } + selectedSourceLevel = originalSourceLevel; + this.minimalJDKVersion = minimalJDKVersion; + } + + public int getSize() { + SourceLevelKey[] sLevels = getSourceLevels(); + return sLevels.length; + } + + public Object getElementAt(int index) { + SourceLevelKey[] sLevels = getSourceLevels(); + assert index >= 0 && index < sLevels.length; + return sLevels[index]; + } + + public Object getSelectedItem() { + for (SourceLevelKey key : getSourceLevels()) { + if (key.getSourceLevel().equals(selectedSourceLevel)) { + return key; + } + } + return null; + } + + public void setSelectedItem(Object obj) { + selectedSourceLevel = (obj == null ? null : ((SourceLevelKey) obj).getSourceLevel()); + fireContentsChanged(this, -1, -1); + } + + public void intervalAdded(ListDataEvent e) { + } + + public void intervalRemoved(ListDataEvent e) { + } + + public void contentsChanged(ListDataEvent e) { + PlatformKey selectedPlatform = (PlatformKey) platformComboBoxModel.getSelectedItem(); + JavaPlatform platform = getPlatform(selectedPlatform); + if (platform != null) { + SpecificationVersion version = platform.getSpecification().getVersion(); + if (selectedSourceLevel != null + && selectedSourceLevel.compareTo(version) > 0 + && !shouldChangePlatform(selectedSourceLevel, version)) { + // restore original + platformComboBoxModel.setSelectedItem(activePlatform); + return; + } else { + originalSourceLevel = null; + } + } + activePlatform = selectedPlatform; + resetCache(); + } + + private void resetCache() { + synchronized (this) { + sourceLevelCache = null; + } + fireContentsChanged(this, -1, -1); + } + + private SourceLevelKey[] getSourceLevels() { + if (sourceLevelCache == null) { + PlatformKey selectedPlatform = (PlatformKey) platformComboBoxModel.getSelectedItem(); + JavaPlatform platform = getPlatform(selectedPlatform); + List sLevels = new ArrayList(); + // if platform == null => broken platform, the source level range is unknown + // the source level combo box should be empty and disabled + boolean selSourceLevelValid = false; + if (platform != null) { + SpecificationVersion version = platform.getSpecification().getVersion(); + int index = INITIAL_VERSION_MINOR; + // #71619 - source level lower than 1.5 won't be shown for Java EE 5 project + if (minimalJDKVersion != null) { + switch (minimalJDKVersion) { + case VERSION_5: + index = INITIAL_VERSION_MINOR_JAVA_EE_5; + break; + default: + break; + } + } + SpecificationVersion template = + new SpecificationVersion(VERSION_PREFIX + Integer.toString(index++)); + boolean origSourceLevelValid = false; + + while (template.compareTo(version) <= 0) { + if (template.equals(originalSourceLevel)) { + origSourceLevelValid = true; + } + if (template.equals(selectedSourceLevel)) { + selSourceLevelValid = true; + } + sLevels.add(new SourceLevelKey(template)); + template = new SpecificationVersion(VERSION_PREFIX + Integer.toString(index++)); + } + if (originalSourceLevel != null && !origSourceLevelValid) { + if (originalSourceLevel.equals(selectedSourceLevel)) { + selSourceLevelValid = true; + } + sLevels.add(new SourceLevelKey(originalSourceLevel, true)); + } + } + sourceLevelCache = sLevels.toArray(new SourceLevelKey[sLevels.size()]); + if (!selSourceLevelValid) { + selectedSourceLevel = sourceLevelCache.length == 0 + ? null : sourceLevelCache[sourceLevelCache.length - 1].getSourceLevel(); + } + } + return sourceLevelCache; + } + + private boolean shouldChangePlatform(SpecificationVersion selectedSourceLevel, + SpecificationVersion platformSourceLevel) { + JButton changeOption = new JButton(NbBundle.getMessage(PlatformUiSupport.class, "CTL_ChangePlatform")); + changeOption.getAccessibleContext().setAccessibleDescription( + NbBundle.getMessage(PlatformUiSupport.class, "AD_ChangePlatform")); + String message = MessageFormat.format( + NbBundle.getMessage(PlatformUiSupport.class, "TXT_ChangePlatform"), + new Object[] {selectedSourceLevel.toString(), platformSourceLevel.toString()}); + return DialogDisplayer.getDefault().notify(new NotifyDescriptor( + message, + NbBundle.getMessage(PlatformUiSupport.class, "TXT_ChangePlatformTitle"), + NotifyDescriptor.DEFAULT_OPTION, + NotifyDescriptor.WARNING_MESSAGE, + new Object[] { + changeOption, + NotifyDescriptor.CANCEL_OPTION + }, + changeOption)) == changeOption; + } + } + + private static final class SourceLevelListCellRenderer implements ListCellRenderer { + + private ListCellRenderer delegate; + + public SourceLevelListCellRenderer() { + delegate = HtmlRenderer.createRenderer(); + } + + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, + boolean cellHasFocus) { + String message; + if (value == null) { + message = ""; //NOI18N + } else { + assert value instanceof SourceLevelKey; + SourceLevelKey key = (SourceLevelKey) value; + if (key.isBroken()) { + message = "" //NOI18N + + NbBundle.getMessage( + PlatformUiSupport.class, "TXT_InvalidSourceLevel", key.getDisplayName()); + } else { + message = key.getDisplayName(); + } + } + return delegate.getListCellRendererComponent(list, message, index, isSelected, cellHasFocus); + } + } + + private static JavaPlatform getPlatform(PlatformKey platformKey) { + return platformKey.platform; + } + + private static JavaPlatform findPlatform(String displayName) { + JavaPlatform[] platforms = JavaPlatformManager.getDefault().getPlatforms( + displayName, new Specification("j2se", null)); //NOI18N + if (platforms.length == 0) { + return null; + } + return platforms[0]; + } +} diff --git a/java.commonapi/src/org/netbeans/modules/java/api/common/util/CommonProjectUtils.java b/java.commonapi/src/org/netbeans/modules/java/api/common/util/CommonProjectUtils.java new file mode 100644 --- /dev/null +++ b/java.commonapi/src/org/netbeans/modules/java/api/common/util/CommonProjectUtils.java @@ -0,0 +1,93 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.java.api.common.util; + +import org.netbeans.api.java.platform.JavaPlatform; +import org.netbeans.api.java.platform.JavaPlatformManager; +import org.netbeans.api.java.platform.Specification; + +/** + * Common project utilities. This is a helper class; all methods are static. + * @author Tomas Mysik + */ +public final class CommonProjectUtils { + + private CommonProjectUtils() { + } + + // XXX copied from J2SEProjectUtilities, should be part of some API probably (JavaPlatformManager?) + /** + * Returns the active platform used by the project or null if the active + * project platform is broken. + * @param activePlatformId the name of platform used by Ant script or null + * for default platform. + * @return active {@link JavaPlatform} or null if the project's platform + * is broken + */ + public static JavaPlatform getActivePlatform(final String activePlatformId) { + final JavaPlatformManager pm = JavaPlatformManager.getDefault(); + if (activePlatformId == null) { + return pm.getDefaultPlatform(); + } + + JavaPlatform[] installedPlatforms = pm.getPlatforms(null, new Specification("j2se", null)); //NOI18N + for (JavaPlatform javaPlatform : installedPlatforms) { + String antName = javaPlatform.getProperties().get("platform.ant.name"); //NOI18N + if (antName != null && antName.equals(activePlatformId)) { + return javaPlatform; + } + } + return null; + } + + /** + * Converts the ant reference to the name of the referenced property. + * @param property the name of the referenced property. + * @return the referenced property. + */ + public static String getAntPropertyName(String property) { + if (property != null + && property.startsWith("${") // NOI18N + && property.endsWith("}")) { // NOI18N + return property.substring(2, property.length() - 1); + } + return property; + } +} diff --git a/java.commonapi/test/build-unit.xml b/java.commonapi/test/build-unit.xml new file mode 100644 --- /dev/null +++ b/java.commonapi/test/build-unit.xml @@ -0,0 +1,44 @@ + + + + + + diff --git a/java.commonapi/test/build.xml b/java.commonapi/test/build.xml new file mode 100644 --- /dev/null +++ b/java.commonapi/test/build.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + diff --git a/java.commonapi/test/cfg-unit.xml b/java.commonapi/test/cfg-unit.xml new file mode 100644 --- /dev/null +++ b/java.commonapi/test/cfg-unit.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + diff --git a/java.commonapi/test/unit/src/org/netbeans/modules/java/api/common/queries/FileEncodingQueryImplTest.java b/java.commonapi/test/unit/src/org/netbeans/modules/java/api/common/queries/FileEncodingQueryImplTest.java new file mode 100644 --- /dev/null +++ b/java.commonapi/test/unit/src/org/netbeans/modules/java/api/common/queries/FileEncodingQueryImplTest.java @@ -0,0 +1,120 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2007 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.java.api.common.queries; + +import java.io.File; +import java.nio.charset.Charset; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.junit.NbTestCase; +import org.netbeans.spi.project.support.ant.AntBasedTestUtil; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.openide.filesystems.FileObject; +import org.netbeans.spi.queries.FileEncodingQueryImplementation; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.EditableProperties; +import org.netbeans.spi.project.support.ant.ProjectGenerator; +import org.openide.filesystems.FileUtil; +import org.openide.util.Mutex; +import org.openide.util.test.MockLookup; + +/** + * Tests for {@link FileEncodingQueryImpl}. + * + * @author Tomas Mysik + */ +public class FileEncodingQueryImplTest extends NbTestCase { + + private FileObject projdir; + private AntProjectHelper helper; + private PropertyEvaluator eval; + private Project prj; + private static final String SOURCE_ENCODING = "source.encoding"; + + public FileEncodingQueryImplTest(String testName) { + super(testName); + } + + @Override + protected void setUp() throws Exception { + MockLookup.setInstances(AntBasedTestUtil.testAntBasedProjectType()); + super.setUp(); + this.clearWorkDir(); + File wd = getWorkDir(); + FileObject scratch = FileUtil.toFileObject(wd); + assertNotNull(wd); + projdir = scratch.createFolder("proj"); + helper = ProjectGenerator.createProject(projdir, "test"); + assertNotNull(helper); + eval = helper.getStandardPropertyEvaluator(); + assertNotNull(eval); + prj = ProjectManager.getDefault().findProject(projdir); + assertNotNull(prj); + } + + public void testFileEncodingQuery() throws Exception { + final Charset UTF_8 = Charset.forName("UTF-8"); + final Charset ISO_8859_2 = Charset.forName("ISO-8859-2"); + + FileObject dummy = projdir.createData("Dummy.java"); + + setProjectCharset(UTF_8); + FileEncodingQueryImplementation fileEncodingQuery = QuerySupport.createFileEncodingQuery(eval, SOURCE_ENCODING); + + Charset enc = fileEncodingQuery.getEncoding(dummy); + assertEquals(UTF_8, enc); + + setProjectCharset(ISO_8859_2); + enc = fileEncodingQuery.getEncoding(dummy); + assertEquals(ISO_8859_2, enc); + } + + private void setProjectCharset(final Charset charset) throws Exception { + ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() { + public Void run() throws Exception { + EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + ep.setProperty(SOURCE_ENCODING, charset.name()); + helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); + ProjectManager.getDefault().saveProject(prj); + return null; + } + }); + } +} diff --git a/java.commonapi/test/unit/src/org/netbeans/modules/java/api/common/queries/JavadocForBinaryQueryImplTest.java b/java.commonapi/test/unit/src/org/netbeans/modules/java/api/common/queries/JavadocForBinaryQueryImplTest.java new file mode 100644 --- /dev/null +++ b/java.commonapi/test/unit/src/org/netbeans/modules/java/api/common/queries/JavadocForBinaryQueryImplTest.java @@ -0,0 +1,137 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2007 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.java.api.common.queries; + +import java.io.File; +import java.net.URL; +import org.netbeans.api.java.queries.JavadocForBinaryQuery.Result; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.junit.NbTestCase; +import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation; +import org.netbeans.spi.project.support.ant.AntBasedTestUtil; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.openide.filesystems.FileObject; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.EditableProperties; +import org.netbeans.spi.project.support.ant.ProjectGenerator; +import org.openide.filesystems.FileStateInvalidException; +import org.openide.filesystems.FileUtil; +import org.openide.util.Mutex; +import org.openide.util.test.MockLookup; + +/** + * Tests for {@link JavadocForBinaryQueryImpl}. + * + * @author Tomas Mysik + */ +public class JavadocForBinaryQueryImplTest extends NbTestCase { + + private FileObject projdir; + private AntProjectHelper helper; + private PropertyEvaluator eval; + private Project prj; + private FileObject builddir; + private static final String BUILD_CLASSES_DIR = "build.classes.dir"; + private static final String JAVADOC_DIR = "dist.javadoc.dir"; + + private static final String JAVADOC_1 = "javadoc1"; + private static final String JAVADOC_2 = "javadoc2"; + + public JavadocForBinaryQueryImplTest(String testName) { + super(testName); + } + + @Override + protected void setUp() throws Exception { + MockLookup.setInstances(AntBasedTestUtil.testAntBasedProjectType()); + super.setUp(); + this.clearWorkDir(); + File wd = getWorkDir(); + FileObject scratch = FileUtil.toFileObject(wd); + assertNotNull(wd); + projdir = scratch.createFolder("proj"); + helper = ProjectGenerator.createProject(projdir, "test"); + assertNotNull(helper); + eval = helper.getStandardPropertyEvaluator(); + assertNotNull(eval); + prj = ProjectManager.getDefault().findProject(projdir); + assertNotNull(prj); + builddir = projdir.createFolder("build"); + assertNotNull(builddir); + } + + public void testJavadocForBinaryQuery() throws Exception { + setProjectDirectory(BUILD_CLASSES_DIR, builddir); + JavadocForBinaryQueryImplementation javadocForBinaryQuery = + QuerySupport.createJavadocForBinaryQuery(helper, eval); + + setProjectDirectory(JAVADOC_DIR, projdir.createFolder(JAVADOC_1)); + Result javadoc = javadocForBinaryQuery.findJavadoc(builddir.getURL()); + assertNotNull(javadoc); + + URL[] roots = javadoc.getRoots(); + assertEquals(1, roots.length); + assertEquals(getJavadocUrl(JAVADOC_1), roots[0]); + + // change javadoc directory + setProjectDirectory(JAVADOC_DIR, projdir.createFolder(JAVADOC_2)); + roots = javadoc.getRoots(); + assertEquals(1, roots.length); + assertEquals(getJavadocUrl(JAVADOC_2), roots[0]); + } + + private URL getJavadocUrl(String javadoc) throws FileStateInvalidException { + return projdir.getFileObject(javadoc).getURL(); + } + + private void setProjectDirectory(final String property, final FileObject directory) throws Exception { + assertTrue(directory.isFolder()); + ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() { + public Void run() throws Exception { + EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + ep.setProperty(property, directory.getName()); + helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); + ProjectManager.getDefault().saveProject(prj); + return null; + } + }); + } +} diff --git a/java.commonapi/test/unit/src/org/netbeans/modules/java/api/common/queries/SourceLevelQueryImplTest.java b/java.commonapi/test/unit/src/org/netbeans/modules/java/api/common/queries/SourceLevelQueryImplTest.java new file mode 100644 --- /dev/null +++ b/java.commonapi/test/unit/src/org/netbeans/modules/java/api/common/queries/SourceLevelQueryImplTest.java @@ -0,0 +1,220 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2007 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.java.api.common.queries; + +import java.beans.PropertyChangeListener; +import java.io.IOException; +import java.net.URL; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import org.netbeans.api.java.classpath.ClassPath; +import org.netbeans.api.java.platform.JavaPlatform; +import org.netbeans.api.java.platform.Specification; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.junit.NbTestCase; +import org.netbeans.modules.java.platform.JavaPlatformProvider; +import org.netbeans.spi.project.support.ant.PropertyUtils; +import org.openide.filesystems.FileObject; +import org.netbeans.api.project.TestUtil; +import org.netbeans.spi.java.classpath.support.ClassPathSupport; +import org.netbeans.spi.java.queries.SourceLevelQueryImplementation; +import org.netbeans.spi.project.support.ant.AntBasedTestUtil; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.EditableProperties; +import org.netbeans.spi.project.support.ant.ProjectGenerator; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.openide.filesystems.FileUtil; +import org.openide.modules.SpecificationVersion; +import org.openide.util.test.MockLookup; + +/** + * Tests for {@link SourceLevelQueryImpl}. + * + * @author Tomas Mysik + */ +public class SourceLevelQueryImplTest extends NbTestCase { + + private static final String JAVAC_SOURCE = "1.2"; + private static final String DEFAULT_JAVAC_SOURCE = "17.2"; + + private static final String TEST_PLATFORM = "TestPlatform"; + private static final String BROKEN_PLATFORM = "BrokenPlatform"; + + private FileObject scratch; + private FileObject projdir; + private AntProjectHelper helper; + private PropertyEvaluator eval; + private Project prj; + + public SourceLevelQueryImplTest(String testName) { + super(testName); + } + + @Override + protected void setUp() throws Exception { + MockLookup.setInstances( + AntBasedTestUtil.testAntBasedProjectType(), + new TestPlatformProvider()); + super.setUp(); + this.clearWorkDir(); + Properties p = System.getProperties(); + if (p.getProperty("netbeans.user") == null) { + p.put("netbeans.user", FileUtil.toFile(TestUtil.makeScratchDir(this)).getAbsolutePath()); + } + } + + @Override + protected void tearDown() throws Exception { + scratch = null; + projdir = null; + super.tearDown(); + } + + + private void prepareProject(String platformName) throws IOException { + scratch = TestUtil.makeScratchDir(this); + projdir = scratch.createFolder("proj"); + helper = ProjectGenerator.createProject(projdir, "test"); + assertNotNull(helper); + prj = ProjectManager.getDefault().findProject(projdir); + assertNotNull(prj); + EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + props.setProperty("javac.source", "${def}"); + props.setProperty("platform.active", platformName); + props.setProperty("def", JAVAC_SOURCE); + helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); + props = PropertyUtils.getGlobalProperties(); + props.put("default.javac.source", DEFAULT_JAVAC_SOURCE); + PropertyUtils.putGlobalProperties(props); + eval = helper.getStandardPropertyEvaluator(); + assertNotNull(eval); + } + + public void testGetSourceLevelWithValidPlatform() throws Exception { + this.prepareProject(TEST_PLATFORM); + + FileObject dummy = projdir.createData("Dummy.java"); + SourceLevelQueryImplementation sourceLevelQuery = QuerySupport.createSourceLevelQuery(eval); + + String sl = sourceLevelQuery.getSourceLevel(dummy); + assertEquals(JAVAC_SOURCE, sl); + } + + public void testGetSourceLevelWithBrokenPlatform() throws Exception { + this.prepareProject(BROKEN_PLATFORM); + + FileObject dummy = projdir.createData("Dummy.java"); + SourceLevelQueryImplementation sourceLevelQuery = QuerySupport.createSourceLevelQuery(eval); + + String sl = sourceLevelQuery.getSourceLevel(dummy); + assertEquals(DEFAULT_JAVAC_SOURCE, sl); + } + + private static class TestPlatformProvider implements JavaPlatformProvider { + + private JavaPlatform platform; + + public void removePropertyChangeListener(PropertyChangeListener listener) { + } + + public void addPropertyChangeListener(PropertyChangeListener listener) { + } + + public JavaPlatform[] getInstalledPlatforms() { + return new JavaPlatform[] { + getDefaultPlatform() + }; + } + + public JavaPlatform getDefaultPlatform() { + if (this.platform == null) { + this.platform = new TestPlatform(); + } + return this.platform; + } + } + + private static class TestPlatform extends JavaPlatform { + + public FileObject findTool(String toolName) { + return null; + } + + public String getVendor() { + return "me"; + } + + public ClassPath getStandardLibraries() { + return ClassPathSupport.createClassPath(new URL[0]); + } + + public Specification getSpecification() { + return new Specification("j2se", new SpecificationVersion("1.5")); + } + + public ClassPath getSourceFolders() { + return null; + } + + public Map getProperties() { + return Collections.singletonMap("platform.ant.name", TEST_PLATFORM); + } + + public List getJavadocFolders() { + return null; + } + + public Collection getInstallFolders() { + return null; + } + + public String getDisplayName() { + return "TestPlatform"; + } + + public ClassPath getBootstrapLibraries() { + return ClassPathSupport.createClassPath(new URL[0]); + } + } +} diff --git a/java.j2seproject/nbproject/project.xml b/java.j2seproject/nbproject/project.xml --- a/java.j2seproject/nbproject/project.xml +++ b/java.j2seproject/nbproject/project.xml @@ -114,6 +114,15 @@ made subject to such option by the copyr 1 1.3 + + + + org.netbeans.modules.java.api.common + + + + 0-1 + 1.0 @@ -284,13 +293,31 @@ made subject to such option by the copyr unit + org.netbeans.api.progress + + + org.netbeans.bootstrap + + + org.netbeans.core + + + org.netbeans.core.startup + + + org.netbeans.libs.xerces + + + org.netbeans.modules.java.api.common + + + org.netbeans.modules.java.j2seproject - org.openide.io - + org.netbeans.modules.masterfs org.netbeans.modules.projectapi @@ -298,59 +325,7 @@ made subject to such option by the copyr - org.netbeans.core - - - org.openide.loaders - - - org.netbeans.modules.masterfs - - - org.netbeans.api.progress - - - org.openide.options - - - org.openide.explorer - - - org.openide.dialogs - - - org.openide.nodes - - - org.openide.text - - - org.openide.awt - - - org.openide.util - - - - - org.openide.actions - - - org.openide.modules - - - org.openide.filesystems - - - - - org.netbeans.core.startup - - - org.netbeans.bootstrap - - - org.netbeans.libs.xerces + org.netbeans.modules.projectui org.netbeans.modules.schema2beans @@ -359,7 +334,45 @@ made subject to such option by the copyr org.netbeans.modules.xml.retriever - org.netbeans.modules.projectui + org.openide.actions + + + org.openide.awt + + + org.openide.dialogs + + + org.openide.explorer + + + org.openide.filesystems + + + + + org.openide.io + + + + org.openide.loaders + + + org.openide.modules + + + org.openide.nodes + + + org.openide.options + + + org.openide.text + + + org.openide.util + + diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEActionProvider.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEActionProvider.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEActionProvider.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEActionProvider.java @@ -73,6 +73,7 @@ import org.netbeans.api.project.ProjectU import org.netbeans.api.project.ProjectUtils; import org.netbeans.api.project.SourceGroup; import org.netbeans.api.project.Sources; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.modules.java.j2seproject.applet.AppletSupport; import org.netbeans.modules.java.j2seproject.classpath.ClassPathProviderImpl; import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; @@ -433,7 +434,7 @@ class J2SEActionProvider implements Acti result=isSetMainClass (project.getSourceRoots().getRoots(), mainClass); } while (result != MainClassStatus.SET_AND_VALID); try { - if (updateHelper.requestSave()) { + if (updateHelper.requestUpdate()) { updateHelper.putProperties(path, ep); ProjectManager.getDefault().saveProject(project); } diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEFileBuiltQuery.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEFileBuiltQuery.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEFileBuiltQuery.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.java.j2seproject; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import org.netbeans.api.project.ProjectManager; -import org.openide.filesystems.FileObject; -import org.netbeans.api.queries.FileBuiltQuery; -import org.netbeans.spi.queries.FileBuiltQueryImplementation; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; -import org.openide.util.Mutex.Action; - - - - - -public class J2SEFileBuiltQuery implements FileBuiltQueryImplementation, PropertyChangeListener { - - private FileBuiltQueryImplementation delegate; - private final AntProjectHelper helper; - private final PropertyEvaluator evaluator; - private final SourceRoots sourceRoots; - private final SourceRoots testRoots; - - J2SEFileBuiltQuery (AntProjectHelper helper, PropertyEvaluator evaluator, - SourceRoots sourceRoots, SourceRoots testRoots) { - assert helper != null && evaluator != null && sourceRoots != null && testRoots != null; - this.helper = helper; - this.evaluator = evaluator; - this.sourceRoots = sourceRoots; - this.testRoots = testRoots; - this.sourceRoots.addPropertyChangeListener (this); - this.testRoots.addPropertyChangeListener (this); - } - - public FileBuiltQuery.Status getStatus(final FileObject file) { - return ProjectManager.mutex().readAccess(new Action() { - public FileBuiltQuery.Status run() { - return getStatusImpl(file); - } - }); - } - - private synchronized FileBuiltQuery.Status getStatusImpl(FileObject file) { - if (this.delegate == null) { - this.delegate = createDelegate (); - } - return this.delegate.getStatus (file); - } - - - private FileBuiltQueryImplementation createDelegate () { - String[] srcRoots = this.sourceRoots.getRootProperties(); - String[] tstRoots = this.testRoots.getRootProperties(); - String[] from = new String [srcRoots.length + tstRoots.length]; - String[] to = new String [srcRoots.length + tstRoots.length]; - for (int i=0; i< srcRoots.length; i++) { - from[i] = "${" + srcRoots[i] + "}/*.java"; // NOI18N - to[i] = "${" + J2SEProjectProperties.BUILD_CLASSES_DIR + "}/*.class"; // NOI18N - } - for (int i=0; i() { - public Integer run() { - synchronized (J2SESharabilityQuery.this) { - if (delegate == null) { - delegate = createDelegate (); - } - return delegate.getSharability(file); - } - } - }); - } - - public void propertyChange(PropertyChangeEvent evt) { - if (SourceRoots.PROP_ROOT_PROPERTIES.equals(evt.getPropertyName())) { - synchronized (this) { - this.delegate = null; - } - } - } - - private SharabilityQueryImplementation createDelegate () { - String[] srcProps = srcRoots.getRootProperties(); - String[] testProps = testRoots.getRootProperties(); - String[] props = new String [srcProps.length + testProps.length]; - for (int i=0; i mainHandle = main.iterator().next(); newMainClass = mainHandle.getQualifiedName(); } - if (newMainClass != null && !newMainClass.equals(oldMainClass) && helper.requestSave() && + if (newMainClass != null && !newMainClass.equals(oldMainClass) && helper.requestUpdate() && // XXX ##84806: ideally should update nbproject/configs/*.properties in this case: eval.getProperty(J2SEConfigurationProvider.PROP_CONFIG) == null) { final String newMainClassFinal = newMainClass; diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/SourceRoots.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/SourceRoots.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/SourceRoots.java +++ /dev/null @@ -1,477 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.java.j2seproject; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URI; -import java.util.Arrays; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.HashMap; -import java.text.MessageFormat; -import org.openide.ErrorManager; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.util.Exceptions; -import org.openide.util.WeakListeners; -import org.openide.util.Mutex; -import org.openide.util.NbBundle; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; -import org.w3c.dom.Document; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.AntProjectEvent; -import org.netbeans.spi.project.support.ant.AntProjectListener; -import org.netbeans.spi.project.support.ant.EditableProperties; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.spi.project.support.ant.ReferenceHelper; -import org.netbeans.api.project.ProjectManager; -import org.netbeans.api.java.project.JavaProjectConstants; - -/** - * This class represents a project source roots. It is used to obtain roots as Ant properties, FileObject's - * or URLs. - * @author Tomas Zezula - */ -public final class SourceRoots { - - public static final String PROP_ROOT_PROPERTIES = "rootProperties"; //NOI18N - public static final String PROP_ROOTS = "roots"; //NOI18N - - public static final String DEFAULT_SOURCE_LABEL = NbBundle.getMessage(SourceRoots.class, "NAME_src.dir"); - public static final String DEFAULT_TEST_LABEL = NbBundle.getMessage(SourceRoots.class, "NAME_test.src.dir"); - - private final UpdateHelper helper; - private final PropertyEvaluator evaluator; - private final ReferenceHelper refHelper; - private final String elementName; - private final String newRootNameTemplate; - private List sourceRootProperties; - private List sourceRootNames; - private List sourceRoots; - private List sourceRootURLs; - private final PropertyChangeSupport support; - private final ProjectMetadataListener listener; - private final boolean isTest; - private final File projectDir; - - /** - * Creates new SourceRoots - * @param helper - * @param evaluator - * @param elementName the name of XML element under which are declared the roots - * @param newRootNameTemplate template for new property name of source root - */ - SourceRoots (UpdateHelper helper, PropertyEvaluator evaluator, ReferenceHelper refHelper, String elementName, boolean isTest, String newRootNameTemplate) { - assert helper != null && evaluator != null && refHelper != null && elementName != null && newRootNameTemplate != null; - this.helper = helper; - this.evaluator = evaluator; - this.refHelper = refHelper; - this.elementName = elementName; - this.isTest = isTest; - this.newRootNameTemplate = newRootNameTemplate; - this.projectDir = FileUtil.toFile(this.helper.getAntProjectHelper().getProjectDirectory()); - this.support = new PropertyChangeSupport(this); - this.listener = new ProjectMetadataListener(); - this.evaluator.addPropertyChangeListener (WeakListeners.propertyChange(this.listener,this.evaluator)); - this.helper.getAntProjectHelper().addAntProjectListener(WeakListeners.create(AntProjectListener.class, this.listener, this.helper)); - } - - - /** - * Returns the display names of soruce roots - * The returned array has the same length as an array returned by the getRootProperties. - * It may contain empty strings but not null. - * @return an array of String - */ - public String[] getRootNames () { - return ProjectManager.mutex().readAccess(new Mutex.Action() { - public String[] run() { - synchronized (SourceRoots.this) { - if (sourceRootNames == null) { - readProjectMetadata(); - } - } - return sourceRootNames.toArray (new String[sourceRootNames.size()]); - } - }); - } - - /** - * Returns names of Ant properties in the project.properties file holding the source roots. - * @return an array of String - */ - public String[] getRootProperties () { - return ProjectManager.mutex().readAccess(new Mutex.Action() { - public String[] run() { - synchronized (SourceRoots.this) { - if (sourceRootProperties == null) { - readProjectMetadata(); - } - return sourceRootProperties.toArray(new String[sourceRootProperties.size()]); - } - } - }); - } - - /** - * Returns the source roots - * @return an array of FileObject - */ - public FileObject[] getRoots () { - return ProjectManager.mutex().readAccess(new Mutex.Action() { - public FileObject[] run () { - synchronized (this) { - //Local caching - if (sourceRoots == null) { - String[] srcProps = getRootProperties(); - List result = new ArrayList(); - for (String p : srcProps) { - String prop = evaluator.getProperty(p); - if (prop != null) { - FileObject f = helper.getAntProjectHelper().resolveFileObject(prop); - if (f == null) { - continue; - } - if (FileUtil.isArchiveFile(f)) { - f = FileUtil.getArchiveRoot(f); - } - result.add(f); - } - } - sourceRoots = Collections.unmodifiableList(result); - } - } - return sourceRoots.toArray(new FileObject[sourceRoots.size()]); - } - }); - } - - /** - * Returns the source roots as URLs. - * @return an array of URL - */ - public URL[] getRootURLs() { - return ProjectManager.mutex().readAccess(new Mutex.Action() { - public URL[] run () { - synchronized (this) { - //Local caching - if (sourceRootURLs == null) { - String[] srcProps = getRootProperties(); - List result = new ArrayList(); - for (int i = 0; i getRootsToProps () { - return ProjectManager.mutex().readAccess(new Mutex.Action>() { - public Map run () { - String[] srcProps = getRootProperties(); - Map result = new HashMap(); - for (int i = 0; i() { - public Void run() { - Map oldRoots2props = getRootsToProps(); - Map newRoots2lab = new HashMap(); - for (int i=0; i0) { - Element root = (Element) rootsNodes.item(0); - ownerElement.removeChild(root); - } - //Remove all unused root properties - List newRoots = Arrays.asList(roots); - Map propsToRemove = new HashMap(oldRoots2props); - propsToRemove.keySet().removeAll(newRoots); - EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - props.keySet().removeAll(propsToRemove.values()); - helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,props); - //Add the new roots - Document doc = ownerElement.getOwnerDocument(); - oldRoots2props.keySet().retainAll(newRoots); - for (URL newRoot : newRoots) { - String rootName = oldRoots2props.get(newRoot); - if (rootName == null) { - //Root is new generate property for it - props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - String[] names = newRoot.getPath().split("/"); //NOI18N - rootName = MessageFormat.format(newRootNameTemplate, new Object[] {names[names.length - 1], ""}); // NOI18N - int rootIndex = 1; - while (props.containsKey(rootName)) { - rootIndex++; - rootName = MessageFormat.format(newRootNameTemplate, new Object[] {names[names.length - 1], rootIndex}); - } - File f = FileUtil.normalizeFile(new File(URI.create(newRoot.toExternalForm()))); - File projDir = FileUtil.toFile(helper.getAntProjectHelper().getProjectDirectory()); - String path = f.getAbsolutePath(); - String prjPath = projDir.getAbsolutePath()+File.separatorChar; - if (path.startsWith(prjPath)) { - path = path.substring(prjPath.length()); - } - else { - path = refHelper.createForeignFileReference(f, JavaProjectConstants.SOURCES_TYPE_JAVA); - props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - } - props.put(rootName,path); - helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,props); - } - Element newRootNode = doc.createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, "root"); //NOI18N - newRootNode.setAttribute("id",rootName); //NOI18N - String label = newRoots2lab.get(newRoot); - if (label != null && label.length()>0 && !label.equals (getRootDisplayName(null,rootName))) { //NOI18N - newRootNode.setAttribute("name",label); //NOI18N - } - ownerElement.appendChild (newRootNode); - } - helper.putPrimaryConfigurationData(cfgEl,true); - return null; - } - } - ); - } - - /** - * Translates root name into display name of source/test root - * @param rootName the name of root got from {@link SourceRoots#getRootNames} - * @param propName the name of property the root is stored in - * @return the label to be displayed - */ - public String getRootDisplayName (String rootName, String propName) { - if (rootName == null || rootName.length() ==0) { - //If the prop is src.dir use the default name - if (isTest && "test.src.dir".equals(propName)) { //NOI18N - rootName = DEFAULT_TEST_LABEL; - } - else if (!isTest && "src.dir".equals(propName)) { //NOI18N - rootName = DEFAULT_SOURCE_LABEL; - } - else { - //If the name is not given, it should be either a relative path in the project dir - //or absolute path when the root is not under the project dir - String propValue = evaluator.getProperty(propName); - File sourceRoot = propValue == null ? null : helper.getAntProjectHelper().resolveFile(propValue); - rootName = createInitialDisplayName(sourceRoot); - } - } - return rootName; - } - - /** - * Creates initial display name of source/test root - * @param sourceRoot the source root - * @return the label to be displayed - */ - public String createInitialDisplayName (File sourceRoot) { - String rootName; - if (sourceRoot != null) { - String srPath = sourceRoot.getAbsolutePath(); - String pdPath = projectDir.getAbsolutePath() + File.separatorChar; - if (srPath.startsWith(pdPath)) { - rootName = srPath.substring(pdPath.length()); - } - else { - rootName = sourceRoot.getAbsolutePath(); - } - } - else { - rootName = isTest ? DEFAULT_TEST_LABEL : DEFAULT_SOURCE_LABEL; - } - return rootName; - } - - /** - * Returns true if this SourceRoots instance represents source roots belonging to - * the tests compilation unit. - * @return boolean - */ - public boolean isTest () { - return this.isTest; - } - - private void resetCache (boolean isXMLChange, String propName) { - boolean fire = false; - synchronized (this) { - //In case of change reset local cache - if (isXMLChange) { - this.sourceRootProperties = null; - this.sourceRootNames = null; - this.sourceRoots = null; - this.sourceRootURLs = null; - fire = true; - } else if (propName == null || (sourceRootProperties != null && sourceRootProperties.contains(propName))) { - this.sourceRoots = null; - this.sourceRootURLs = null; - fire = true; - } - } - if (fire) { - if (isXMLChange) { - this.support.firePropertyChange (PROP_ROOT_PROPERTIES,null,null); - } - this.support.firePropertyChange (PROP_ROOTS,null,null); - } - } - - private void readProjectMetadata () { - Element cfgEl = helper.getPrimaryConfigurationData(true); - NodeList nl = cfgEl.getElementsByTagNameNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, elementName); - assert nl.getLength() == 0 || nl.getLength() == 1 : "Illegal project.xml"; //NOI18N - List rootProps = new ArrayList(); - List rootNames = new ArrayList(); - // It can be 0 in the case when the project is created by J2SEProjectGenerator and not yet customized - if (nl.getLength()==1) { - NodeList roots = ((Element)nl.item(0)).getElementsByTagNameNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, "root"); //NOI18N - for (int i=0; i 0 : "Illegal project.xml"; - rootProps.add(value); - value = root.getAttribute("name"); //NOI18N - rootNames.add (value); - } - } - this.sourceRootProperties = Collections.unmodifiableList(rootProps); - this.sourceRootNames = Collections.unmodifiableList(rootNames); - } - - private class ProjectMetadataListener implements PropertyChangeListener,AntProjectListener { - - public void propertyChange(PropertyChangeEvent evt) { - resetCache (false,evt.getPropertyName()); - } - - public void configurationXmlChanged(AntProjectEvent ev) { - resetCache (true,null); - } - - public void propertiesChanged(AntProjectEvent ev) { - //Handled by propertyChange - } - } - -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/UpdateHelper.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/UpdateHelper.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/UpdateHelper.java +++ /dev/null @@ -1,420 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.java.j2seproject; - -import java.io.IOException; -import javax.swing.JButton; -import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; -import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; -import org.openide.util.Exceptions; -import org.openide.util.MutexException; -import org.w3c.dom.Comment; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.util.NbBundle; -import org.openide.util.Mutex; -import org.netbeans.api.project.Project; -import org.netbeans.api.project.ProjectManager; -import org.netbeans.spi.project.AuxiliaryConfiguration; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.EditableProperties; - - -/** - * Proxy for the AntProjectHelper which defers the update of the project metadata - * to explicit user action. Currently it is hard coded for update from - * "http://www.netbeans.org/ns/j2se-project/1" to "http://www.netbeans.org/ns/j2se-project/2". - * In future it should define plugable SPI. - */ -public class UpdateHelper { - - private static final boolean TRANSPARENT_UPDATE = Boolean.getBoolean("j2seproject.transparentUpdate"); - private static final String BUILD_NUMBER = System.getProperty("netbeans.buildnumber"); // NOI18N - private static final String MINIMUM_ANT_VERSION_ELEMENT = "minimum-ant-version"; - - private final Project project; - private final AntProjectHelper helper; - private final AuxiliaryConfiguration cfg; - private final GeneratedFilesHelper genFileHelper; - private final Notifier notifier; - private boolean alreadyAskedInWriteAccess; - private Boolean isCurrent; - private Element cachedElement; - - /** - * Creates new UpdateHelper - * @param project - * @param helper AntProjectHelper - * @param cfg AuxiliaryConfiguration - * @param genFileHelper GeneratedFilesHelper - * @param notifier used to ask user about project update - */ - UpdateHelper (Project project, AntProjectHelper helper, AuxiliaryConfiguration cfg, GeneratedFilesHelper genFileHelper, Notifier notifier) { - assert project != null && helper != null && cfg != null && genFileHelper != null && notifier != null; - this.project = project; - this.helper = helper; - this.cfg = cfg; - this.genFileHelper = genFileHelper; - this.notifier = notifier; - } - - /** - * Returns the AntProjectHelper.getProperties(), {@link AntProjectHelper#getProperties(String)} - * @param path a relative URI in the project directory. - * @return a set of properties - */ - public EditableProperties getProperties (final String path) { - //Properties are the same in both j2seproject/1 and j2seproject/2 - return ProjectManager.mutex().readAccess(new Mutex.Action(){ - public EditableProperties run() { - if (!isCurrent() && AntProjectHelper.PROJECT_PROPERTIES_PATH.equals(path)) { //Only project properties were changed - return getUpdatedProjectProperties (); - } - else { - return helper.getProperties(path); - } - } - }); - } - - /** - * In the case that the project is of current version or the properties are not {@link AntProjectHelper#PROJECT_PROPERTIES_PATH} - * it calls AntProjectHelper.putProperties(), {@link AntProjectHelper#putProperties(String, EditableProperties)} - * otherwise it asks user to updata project. If the user agrees with the project update, it does the update and calls - * AntProjectHelper.putProperties(). - * @param path a relative URI in the project directory. - * @param props a set of properties - */ - public void putProperties (final String path, final EditableProperties props) { - ProjectManager.mutex().writeAccess( - new Runnable () { - public void run() { - if (isCurrent() || !AntProjectHelper.PROJECT_PROPERTIES_PATH.equals(path)) { //Only project props should cause update - helper.putProperties(path,props); - } - else if (canUpdate()) { - try { - saveUpdate (); - helper.putProperties(path,props); - } catch (IOException ioe) { - Exceptions.printStackTrace(ioe); - } - } - } - }); - } - - /** - * In the case that the project is of current version or shared is false it delegates to - * AntProjectHelper.getPrimaryConfigurationData(), {@link AntProjectHelper#getPrimaryConfigurationData(boolean)}. - * Otherwise it creates an in memory update of shared configuration data and returns it. - * @param shared if true, refers to project.xml, else refers to - * private.xml - * @return the configuration data that is available - */ - public Element getPrimaryConfigurationData (final boolean shared) { - return ProjectManager.mutex().readAccess(new Mutex.Action(){ - public Element run() { - if (!shared || isCurrent()) { //Only shared props should cause update - return helper.getPrimaryConfigurationData(shared); - } - else { - return getUpdatedSharedConfigurationData (); - } - } - }); - } - - /** - * In the case that the project is of current version or shared is false it calls AntProjectHelper.putPrimaryConfigurationData(), - * {@link AntProjectHelper#putPrimaryConfigurationData(Element, boolean)}. - * Otherwise it asks user to update the project. If the user agrees with the project update, it does the update and calls - * AntProjectHelper.PrimaryConfigurationData(). - * @param element the configuration data - * @param shared if true, refers to project.xml, else refers to - * private.xml - */ - public void putPrimaryConfigurationData (final Element element, final boolean shared) { - ProjectManager.mutex().writeAccess(new Runnable () { - public void run () { - if (!shared || isCurrent()) { - helper.putPrimaryConfigurationData(element, shared); - } else if (canUpdate()) { - try { - saveUpdate (); - helper.putPrimaryConfigurationData(element, shared); - } catch (IOException ioe) { - Exceptions.printStackTrace(ioe); - } - } - } - }); - } - - /** - * Returns an AntProjectHelper. The helper may not be used for accessing/storing project metadata. - * For project metadata manipulation the UpdateHelper must be used. - * @return AntProjectHelper - */ - public AntProjectHelper getAntProjectHelper () { - return this.helper; - } - - /** - * Request an saving of update. If the project is not of current version the user will be asked to update the project. - * If the user agrees with an update the project is updated. - * @return true if the metadata are of current version or updated - */ - public boolean requestSave () throws IOException { - try { - return ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() { - public Boolean run() throws IOException { - if (isCurrent()) { - return Boolean.TRUE; - } - if (!canUpdate()) { - return Boolean.FALSE; - } - saveUpdate(); - return Boolean.TRUE; - } - }).booleanValue(); - - } catch (MutexException ex) { - Exception inner = ex.getException(); - if (inner instanceof IOException) { - throw (IOException) inner; - } - else { - throw (RuntimeException) inner; - } - } - } - - /** - * Returns true if the project is of current version. - * @return true if the project is of current version, otherwise false. - */ - public boolean isCurrent () { - return ProjectManager.mutex().readAccess(new Mutex.Action() { - public Boolean run() { - synchronized (this) { - if (isCurrent == null) { - if ((cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/1",true) != null) || - (cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/2",true) != null)) { - isCurrent = Boolean.FALSE; - } else { - isCurrent = Boolean.TRUE; - } - } - return isCurrent; - } - } - }).booleanValue(); - } - - private boolean canUpdate () { - if (TRANSPARENT_UPDATE) { - return true; - } - //Ask just once under a single write access - if (alreadyAskedInWriteAccess) { - return false; - } - else { - boolean canUpdate = this.notifier.canUpdate(); - if (!canUpdate) { - alreadyAskedInWriteAccess = true; - ProjectManager.mutex().postReadRequest(new Runnable() { - public void run() { - alreadyAskedInWriteAccess = false; - } - }); - } - return canUpdate; - } - } - - private void saveUpdate () throws IOException { - this.helper.putPrimaryConfigurationData(getUpdatedSharedConfigurationData(),true); - this.cfg.removeConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/1",true); //NOI18N - this.cfg.removeConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/2",true); //NOI18N - ProjectManager.getDefault().saveProject (this.project); - synchronized(this) { - this.isCurrent = Boolean.TRUE; - } - } - - private synchronized Element getUpdatedSharedConfigurationData () { - if (cachedElement == null) { - Element oldRoot = this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/1",true); //NOI18N - if (oldRoot != null) { - Document doc = oldRoot.getOwnerDocument(); - Element newRoot = doc.createElementNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N - copyDocument (doc, oldRoot, newRoot); - Element sourceRoots = doc.createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N - Element root = doc.createElementNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N - root.setAttribute ("id","src.dir"); //NOI18N - sourceRoots.appendChild(root); - newRoot.appendChild (sourceRoots); - Element testRoots = doc.createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"test-roots"); //NOI18N - root = doc.createElementNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N - root.setAttribute ("id","test.src.dir"); //NOI18N - testRoots.appendChild (root); - newRoot.appendChild (testRoots); - cachedElement = updateMinAntVersion (newRoot, doc); - } else { - oldRoot = this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/2",true); //NOI18N - if (oldRoot != null) { - Document doc = oldRoot.getOwnerDocument(); - Element newRoot = doc.createElementNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N - copyDocument (doc, oldRoot, newRoot); - cachedElement = updateMinAntVersion (newRoot, doc); - } - } - } - return cachedElement; - } - - private synchronized EditableProperties getUpdatedProjectProperties () { - EditableProperties cachedProperties = this.helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - //The javadoc.additionalparam was not in NB 4.0 - if (cachedProperties.get (J2SEProjectProperties.JAVADOC_ADDITIONALPARAM)==null) { - cachedProperties.put (J2SEProjectProperties.JAVADOC_ADDITIONALPARAM,""); //NOI18N - } - if (cachedProperties.get ("build.generated.dir")==null) { //NOI18N - cachedProperties.put ("build.generated.dir","${build.dir}/generated"); //NOI18N - } - if (cachedProperties.get ("meta.inf.dir")==null) { //NOI18N - cachedProperties.put ("meta.inf.dir","${src.dir}/META-INF"); //NOI18N - } - return cachedProperties; - } - - private static void copyDocument (Document doc, Element from, Element to) { - NodeList nl = from.getChildNodes(); - int length = nl.getLength(); - for (int i=0; i< length; i++) { - Node node = nl.item (i); - Node newNode = null; - switch (node.getNodeType()) { - case Node.ELEMENT_NODE: - Element oldElement = (Element) node; - newNode = doc.createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName()); - NamedNodeMap m = oldElement.getAttributes(); - Element newElement = (Element) newNode; - for (int index = 0; index < m.getLength(); index++) { - Node attr = m.item(index); - newElement.setAttribute(attr.getNodeName(), attr.getNodeValue()); - } - copyDocument(doc,oldElement,newElement); - break; - case Node.TEXT_NODE: - Text oldText = (Text) node; - newNode = doc.createTextNode(oldText.getData()); - break; - case Node.COMMENT_NODE: - Comment oldComment = (Comment) node; - newNode = doc.createComment(oldComment.getData()); - break; - } - if (newNode != null) { - to.appendChild (newNode); - } - } - } - - private static Element updateMinAntVersion (final Element root, final Document doc) { - NodeList list = root.getElementsByTagNameNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT); - if (list.getLength() == 1) { - Element me = (Element) list.item(0); - list = me.getChildNodes(); - if (list.getLength() == 1) { - me.replaceChild (doc.createTextNode(J2SEProjectGenerator.MINIMUM_ANT_VERSION), list.item(0)); - return root; - } - } - assert false : "Invalid project file"; //NOI18N - return root; - } - - /** - * Creates an default Notifier. The default notifier displays a dialog warning user about project update. - * @return notifier - */ - public static Notifier createDefaultNotifier () { - return new Notifier() { - public boolean canUpdate() { - JButton updateOption = new JButton (NbBundle.getMessage(UpdateHelper.class, "CTL_UpdateOption")); - updateOption.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(UpdateHelper.class, "AD_UpdateOption")); - return DialogDisplayer.getDefault().notify( - new NotifyDescriptor (NbBundle.getMessage(UpdateHelper.class,"TXT_ProjectUpdate", BUILD_NUMBER), - NbBundle.getMessage(UpdateHelper.class,"TXT_ProjectUpdateTitle"), - NotifyDescriptor.DEFAULT_OPTION, - NotifyDescriptor.WARNING_MESSAGE, - new Object[] { - updateOption, - NotifyDescriptor.CANCEL_OPTION - }, - updateOption)) == updateOption; - } - }; - } - - /** - * Interface used by the UpdateHelper to ask user about - * the project update. - */ - public static interface Notifier { - /** - * Asks user to update the project - * @return true if the project should be updated - */ - public boolean canUpdate (); - } -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/UpdateProjectImpl.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/UpdateProjectImpl.java new file mode 100644 --- /dev/null +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/UpdateProjectImpl.java @@ -0,0 +1,256 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.java.j2seproject; + +import java.io.IOException; +import javax.swing.JButton; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.modules.java.api.common.ant.UpdateImplementation; +import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; +import org.netbeans.spi.project.AuxiliaryConfiguration; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.EditableProperties; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.util.Mutex; +import org.openide.util.NbBundle; +import org.w3c.dom.Comment; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +/** + * + * @author Tomas Mysik + */ +public class UpdateProjectImpl implements UpdateImplementation { + + private static final boolean TRANSPARENT_UPDATE = Boolean.getBoolean("j2seproject.transparentUpdate"); + private static final String BUILD_NUMBER = System.getProperty("netbeans.buildnumber"); // NOI18N + private static final String MINIMUM_ANT_VERSION_ELEMENT = "minimum-ant-version"; + + private final Project project; + private final AntProjectHelper helper; + private final AuxiliaryConfiguration cfg; + private boolean alreadyAskedInWriteAccess; + private Boolean isCurrent; + private Element cachedElement; + + /** + * Creates new UpdateHelper + * @param project + * @param helper AntProjectHelper + * @param cfg AuxiliaryConfiguration + * @param genFileHelper GeneratedFilesHelper + * @param notifier used to ask user about project update + */ + UpdateProjectImpl(Project project, AntProjectHelper helper, AuxiliaryConfiguration cfg) { + assert project != null && helper != null && cfg != null; + this.project = project; + this.helper = helper; + this.cfg = cfg; + } + + /** + * Returns true if the project is of current version. + * @return true if the project is of current version, otherwise false. + */ + public boolean isCurrent () { + return ProjectManager.mutex().readAccess(new Mutex.Action() { + public Boolean run() { + synchronized (this) { + if (isCurrent == null) { + if ((cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/1",true) != null) || + (cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/2",true) != null)) { + isCurrent = Boolean.FALSE; + } else { + isCurrent = Boolean.TRUE; + } + } + return isCurrent; + } + } + }).booleanValue(); + } + + public boolean canUpdate () { + if (TRANSPARENT_UPDATE) { + return true; + } + //Ask just once under a single write access + if (alreadyAskedInWriteAccess) { + return false; + } + else { + boolean canUpdate = showUpdateDialog(); + if (!canUpdate) { + alreadyAskedInWriteAccess = true; + ProjectManager.mutex().postReadRequest(new Runnable() { + public void run() { + alreadyAskedInWriteAccess = false; + } + }); + } + return canUpdate; + } + } + + public void saveUpdate(final EditableProperties props) throws IOException { + this.helper.putPrimaryConfigurationData(getUpdatedSharedConfigurationData(),true); + this.cfg.removeConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/1",true); //NOI18N + this.cfg.removeConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/2",true); //NOI18N + ProjectManager.getDefault().saveProject (this.project); + synchronized(this) { + this.isCurrent = Boolean.TRUE; + } + } + + public synchronized Element getUpdatedSharedConfigurationData () { + if (cachedElement == null) { + Element oldRoot = this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/1",true); //NOI18N + if (oldRoot != null) { + Document doc = oldRoot.getOwnerDocument(); + Element newRoot = doc.createElementNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N + copyDocument (doc, oldRoot, newRoot); + Element sourceRoots = doc.createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N + Element root = doc.createElementNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N + root.setAttribute ("id","src.dir"); //NOI18N + sourceRoots.appendChild(root); + newRoot.appendChild (sourceRoots); + Element testRoots = doc.createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"test-roots"); //NOI18N + root = doc.createElementNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N + root.setAttribute ("id","test.src.dir"); //NOI18N + testRoots.appendChild (root); + newRoot.appendChild (testRoots); + cachedElement = updateMinAntVersion (newRoot, doc); + } else { + oldRoot = this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/2",true); //NOI18N + if (oldRoot != null) { + Document doc = oldRoot.getOwnerDocument(); + Element newRoot = doc.createElementNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N + copyDocument (doc, oldRoot, newRoot); + cachedElement = updateMinAntVersion (newRoot, doc); + } + } + } + return cachedElement; + } + + public synchronized EditableProperties getUpdatedProjectProperties () { + EditableProperties cachedProperties = this.helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + //The javadoc.additionalparam was not in NB 4.0 + if (cachedProperties.get (J2SEProjectProperties.JAVADOC_ADDITIONALPARAM)==null) { + cachedProperties.put (J2SEProjectProperties.JAVADOC_ADDITIONALPARAM,""); //NOI18N + } + if (cachedProperties.get ("build.generated.dir")==null) { //NOI18N + cachedProperties.put ("build.generated.dir","${build.dir}/generated"); //NOI18N + } + if (cachedProperties.get ("meta.inf.dir")==null) { //NOI18N + cachedProperties.put ("meta.inf.dir","${src.dir}/META-INF"); //NOI18N + } + return cachedProperties; + } + + private static void copyDocument (Document doc, Element from, Element to) { + NodeList nl = from.getChildNodes(); + int length = nl.getLength(); + for (int i=0; i< length; i++) { + Node node = nl.item (i); + Node newNode = null; + switch (node.getNodeType()) { + case Node.ELEMENT_NODE: + Element oldElement = (Element) node; + newNode = doc.createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName()); + NamedNodeMap m = oldElement.getAttributes(); + Element newElement = (Element) newNode; + for (int index = 0; index < m.getLength(); index++) { + Node attr = m.item(index); + newElement.setAttribute(attr.getNodeName(), attr.getNodeValue()); + } + copyDocument(doc,oldElement,newElement); + break; + case Node.TEXT_NODE: + Text oldText = (Text) node; + newNode = doc.createTextNode(oldText.getData()); + break; + case Node.COMMENT_NODE: + Comment oldComment = (Comment) node; + newNode = doc.createComment(oldComment.getData()); + break; + } + if (newNode != null) { + to.appendChild (newNode); + } + } + } + + private static Element updateMinAntVersion (final Element root, final Document doc) { + NodeList list = root.getElementsByTagNameNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT); + if (list.getLength() == 1) { + Element me = (Element) list.item(0); + list = me.getChildNodes(); + if (list.getLength() == 1) { + me.replaceChild (doc.createTextNode(J2SEProjectGenerator.MINIMUM_ANT_VERSION), list.item(0)); + return root; + } + } + assert false : "Invalid project file"; //NOI18N + return root; + } + + private boolean showUpdateDialog() { + JButton updateOption = new JButton (NbBundle.getMessage(UpdateProjectImpl.class, "CTL_UpdateOption")); + updateOption.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(UpdateProjectImpl.class, "AD_UpdateOption")); + return DialogDisplayer.getDefault().notify( + new NotifyDescriptor (NbBundle.getMessage(UpdateProjectImpl.class,"TXT_ProjectUpdate", BUILD_NUMBER), + NbBundle.getMessage(UpdateProjectImpl.class,"TXT_ProjectUpdateTitle"), + NotifyDescriptor.DEFAULT_OPTION, + NotifyDescriptor.WARNING_MESSAGE, + new Object[] { + updateOption, + NotifyDescriptor.CANCEL_OPTION + }, + updateOption)) == updateOption; + } +} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/ClassPathProviderImpl.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/ClassPathProviderImpl.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/ClassPathProviderImpl.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/ClassPathProviderImpl.java @@ -47,12 +47,12 @@ import java.util.HashMap; import java.util.HashMap; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.project.SourceGroup; +import org.netbeans.modules.java.api.common.SourceRoots; import org.netbeans.spi.java.classpath.ClassPathFactory; import org.netbeans.spi.java.classpath.ClassPathProvider; import org.netbeans.spi.java.project.classpath.support.ProjectClassPathSupport; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.modules.java.j2seproject.SourceRoots; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.WeakListeners; diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/ClassPathSupport.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/ClassPathSupport.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/ClassPathSupport.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/ClassPathSupport.java @@ -54,14 +54,12 @@ import org.netbeans.api.project.ant.AntA import org.netbeans.api.project.ant.AntArtifact; import org.netbeans.api.project.libraries.Library; import org.netbeans.api.project.libraries.LibraryManager; -import org.netbeans.api.queries.CollocationQuery; -import org.netbeans.modules.java.j2seproject.UpdateHelper; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.EditableProperties; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.PropertyUtils; import org.netbeans.spi.project.support.ant.ReferenceHelper; -import org.openide.filesystems.FileUtil; /** * diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathModifier.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathModifier.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathModifier.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathModifier.java @@ -52,15 +52,13 @@ import java.util.logging.Logger; import java.util.logging.Logger; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.project.JavaProjectConstants; -import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectManager; import org.netbeans.api.project.SourceGroup; import org.netbeans.api.project.Sources; import org.netbeans.api.project.ant.AntArtifact; import org.netbeans.api.project.libraries.Library; -import org.netbeans.api.project.libraries.LibraryManager; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.modules.java.j2seproject.J2SEProject; -import org.netbeans.modules.java.j2seproject.UpdateHelper; import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; import org.netbeans.spi.java.project.classpath.ProjectClassPathModifierImplementation; import org.netbeans.spi.project.libraries.support.LibrariesSupport; diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/SourcePathImplementation.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/SourcePathImplementation.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/SourcePathImplementation.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/SourcePathImplementation.java @@ -52,10 +52,10 @@ import java.net.URL; import java.net.URL; import java.util.Iterator; import java.util.StringTokenizer; +import org.netbeans.modules.java.api.common.SourceRoots; import org.netbeans.spi.java.classpath.ClassPathImplementation; import org.netbeans.spi.java.classpath.PathResourceImplementation; import org.netbeans.spi.java.classpath.support.ClassPathSupport; -import org.netbeans.modules.java.j2seproject.SourceRoots; import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; import org.netbeans.spi.java.classpath.FilteringPathResourceImplementation; import org.netbeans.spi.project.support.ant.AntProjectHelper; diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/BinaryForSourceQueryImpl.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/BinaryForSourceQueryImpl.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/BinaryForSourceQueryImpl.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/BinaryForSourceQueryImpl.java @@ -48,11 +48,10 @@ import java.net.URL; import java.net.URL; import java.util.HashMap; import java.util.Map; -import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.netbeans.api.java.queries.BinaryForSourceQuery; import org.netbeans.api.java.queries.BinaryForSourceQuery.Result; -import org.netbeans.modules.java.j2seproject.SourceRoots; +import org.netbeans.modules.java.api.common.SourceRoots; import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; import org.netbeans.spi.java.queries.BinaryForSourceQueryImplementation; import org.netbeans.spi.project.support.ant.AntProjectHelper; diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/CompiledSourceForBinaryQuery.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/CompiledSourceForBinaryQuery.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/CompiledSourceForBinaryQuery.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.java.j2seproject.queries; - -import java.io.File; -import java.util.Arrays; -import java.util.List; -import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.openide.ErrorManager; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import java.net.URL; -import java.net.MalformedURLException; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeEvent; -import java.util.ArrayList; -import java.util.Map; -import java.util.HashMap; -import javax.swing.event.ChangeListener; -import javax.swing.event.ChangeEvent; -import org.netbeans.api.java.queries.SourceForBinaryQuery; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.modules.java.j2seproject.SourceRoots; -import org.openide.filesystems.URLMapper; -import org.openide.util.ChangeSupport; - -/** - * Finds sources corresponding to binaries in a J2SE project. - * @author Jesse Glick, Tomas Zezula - */ -public class CompiledSourceForBinaryQuery implements SourceForBinaryQueryImplementation { - - private static final String PROP_BUILD_DIR = "build.dir"; //NOI18N - - private final AntProjectHelper helper; - private final PropertyEvaluator evaluator; - private final SourceRoots sourceRoots; - private final SourceRoots testRoots; - private Map cache = new HashMap(); - - public CompiledSourceForBinaryQuery(AntProjectHelper helper, PropertyEvaluator evaluator, SourceRoots srcRoots, SourceRoots testRoots) { - this.helper = helper; - this.evaluator = evaluator; - this.sourceRoots = srcRoots; - this.testRoots = testRoots; - } - - public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) { - if (FileUtil.getArchiveFile(binaryRoot) != null) { - binaryRoot = FileUtil.getArchiveFile(binaryRoot); - // XXX check whether this is really the root - } - SourceForBinaryQuery.Result res = cache.get(binaryRoot); - if (res != null) { - return res; - } - SourceRoots src = null; - if (hasSources(binaryRoot,"build.classes.dir")) { //NOI18N - src = this.sourceRoots; - } - else if (hasSources (binaryRoot,"dist.jar")) { //NOI18N - src = this.sourceRoots; - } - else if (hasSources (binaryRoot,"build.test.classes.dir")) { //NOI18N - src = this.testRoots; - } - if (src == null) { - return null; - } - else { - res = new Result (src); - cache.put (binaryRoot, res); - return res; - } - } - - - private boolean hasSources (URL binaryRoot, String binaryProperty) { - try { - String outDir = evaluator.getProperty(binaryProperty); - if (outDir != null) { - File f = helper.resolveFile (outDir); - URL url = f.toURI().toURL(); - if (!f.exists() && !f.getPath().toLowerCase().endsWith(".jar")) { // NOI18N - // non-existing - assert !url.toExternalForm().endsWith("/") : f; // NOI18N - url = new URL(url.toExternalForm() + "/"); // NOI18N - } - if (url.equals (binaryRoot)) { - return true; - } - } - } catch (MalformedURLException malformedURL) { - ErrorManager.getDefault().notify(malformedURL); - } - return false; - } - - private class Result implements SourceForBinaryQuery.Result, PropertyChangeListener { - - private final ChangeSupport changeSupport = new ChangeSupport(this); - private SourceRoots sourceRoots; - - public Result (SourceRoots sourceRoots) { - this.sourceRoots = sourceRoots; - this.sourceRoots.addPropertyChangeListener(this); - } - - public FileObject[] getRoots () { - //todo: May need to cache the result - List result = new ArrayList(); - result.addAll(Arrays.asList(this.sourceRoots.getRoots())); - try { - String buildDir = evaluator.getProperty(PROP_BUILD_DIR); - if (buildDir != null) { - // generated/wsclient - File f = new File (helper.resolveFile (buildDir),"generated/wsclient"); //NOI18N - URL url = f.toURI().toURL(); - if (!f.exists()) { //NOI18N - assert !url.toExternalForm().endsWith("/"); //NOI18N - url = new URL (url.toExternalForm()+'/'); //NOI18N - } - FileObject root = URLMapper.findFileObject(url); - if (root != null) { - result.add(root); - } - - // generated/wsimport/client - f = new File (helper.resolveFile(buildDir),"generated/wsimport/client"); //NOI18N - url = f.toURI().toURL(); - if (!f.exists()) { //NOI18N - assert !url.toExternalForm().endsWith("/"); //NOI18N - url = new URL (url.toExternalForm()+'/'); //NOI18N - } - root = URLMapper.findFileObject(url); - if (root != null) { - result.add(root); - } - - // generated/addons/jaxb - f = new File (helper.resolveFile (buildDir),"generated/addons/jaxb"); //NOI18N - url = f.toURI().toURL(); - if (!f.exists()) { - assert !url.toExternalForm().endsWith("/"); //NOI18N - url = new URL (url.toExternalForm()+'/'); //NOI18N - } - root = URLMapper.findFileObject(url); - if (root != null) { - result.add(root); - } - - } - } catch (MalformedURLException ex) { - ErrorManager.getDefault ().notify (ex); - } - return result.toArray(new FileObject[result.size()]); - } - - public void addChangeListener (ChangeListener l) { - changeSupport.addChangeListener(l); - } - - public void removeChangeListener (ChangeListener l) { - changeSupport.removeChangeListener(l); - } - - public void propertyChange(PropertyChangeEvent evt) { - if (SourceRoots.PROP_ROOTS.equals(evt.getPropertyName())) { - this.changeSupport.fireChange (); - } - } - - } - -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/J2SEProjectEncodingQueryImpl.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/J2SEProjectEncodingQueryImpl.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/J2SEProjectEncodingQueryImpl.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.java.j2seproject.queries; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.nio.charset.Charset; -import java.nio.charset.IllegalCharsetNameException; -import java.nio.charset.UnsupportedCharsetException; -import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; -import org.netbeans.spi.queries.FileEncodingQueryImplementation; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.openide.filesystems.FileObject; - -/** - * - * @author Tomas Zezula - */ -public class J2SEProjectEncodingQueryImpl extends FileEncodingQueryImplementation implements PropertyChangeListener { - - - private final PropertyEvaluator eval; - private Charset cache; - - /** Creates a new instance of J2SEProjectEncodingQueryImpl */ - public J2SEProjectEncodingQueryImpl(final PropertyEvaluator eval) { - assert eval != null; - this.eval = eval; - this.eval.addPropertyChangeListener(this); - } - - public Charset getEncoding(FileObject file) { - assert file != null; - synchronized (this) { - if (cache != null) { - return cache; - } - } - String enc = eval.getProperty(J2SEProjectProperties.SOURCE_ENCODING); - synchronized (this) { - if (cache == null) { - try { - //From discussion with K. Frank the project returns Charset.defaultCharset () - //for old j2se projects. The old project used system encoding => Charset.defaultCharset () - //should work for most users. - cache = enc == null ? Charset.defaultCharset() : Charset.forName(enc); - } catch (IllegalCharsetNameException exception) { - return null; - } - catch (UnsupportedCharsetException exception) { - return null; - } - } - return cache; - } - } - - public void propertyChange(PropertyChangeEvent event) { - String propName = event.getPropertyName(); - if (propName == null || propName.equals(J2SEProjectProperties.SOURCE_ENCODING)) { - synchronized (this) { - cache = null; - } - } - } - -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/JavadocForBinaryQueryImpl.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/JavadocForBinaryQueryImpl.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/JavadocForBinaryQueryImpl.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.java.j2seproject.queries; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.File; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.openide.filesystems.FileUtil; -import java.net.URL; -import java.net.MalformedURLException; -import javax.swing.event.ChangeListener; -import org.netbeans.api.java.queries.JavadocForBinaryQuery; -import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.openide.util.ChangeSupport; -import org.openide.util.Exceptions; -import org.openide.util.WeakListeners; - -/** - * Finds Javadoc (if it is built) corresponding to binaries in J2SE project. - * @author David Konecny, Jesse Glick - */ -public class JavadocForBinaryQueryImpl implements JavadocForBinaryQueryImplementation { - - private static final String PROP_JAVADOC_DIR = "dist.javadoc.dir"; //NOI18N - - private final AntProjectHelper helper; - private final PropertyEvaluator evaluator; - - public JavadocForBinaryQueryImpl(AntProjectHelper helper, PropertyEvaluator evaluator) { - this.helper = helper; - this.evaluator = evaluator; - } - - public JavadocForBinaryQuery.Result findJavadoc(final URL binaryRoot) { - - class R implements JavadocForBinaryQuery.Result, PropertyChangeListener { - - private final ChangeSupport changeSupport = new ChangeSupport(this); - private URL[] result; - private long eventId; - - public R () { - JavadocForBinaryQueryImpl.this.evaluator.addPropertyChangeListener (WeakListeners.propertyChange(this,JavadocForBinaryQueryImpl.this.evaluator)); - } - - public URL[] getRoots() { - long _eventId; - synchronized (this) { - if (this.result != null) { - return this.result; - } - _eventId = eventId; - } - URL[] _result; - String javadocDir = evaluator.getProperty(PROP_JAVADOC_DIR); - if (javadocDir != null) { - File f = helper.resolveFile(javadocDir); - try { - URL url = f.toURI().toURL(); - if (!f.exists()) { - assert !url.toExternalForm().endsWith("/") : f; // NOI18N - url = new URL(url.toExternalForm() + "/"); // NOI18N - } - _result = new URL[] {url}; - } catch (MalformedURLException e) { - _result = new URL[0]; - Exceptions.printStackTrace(e); - } - } - else { - _result = new URL[0]; - } - synchronized (this) { - if (_eventId == eventId) { - if (this.result == null) { - this.result = _result; - } - return this.result; - } - else { - return _result; - } - - } - - } - public void addChangeListener(final ChangeListener l) { - assert l != null; - changeSupport.addChangeListener(l); - } - public void removeChangeListener(final ChangeListener l) { - assert l != null; - changeSupport.removeChangeListener(l); - } - - public void propertyChange (final PropertyChangeEvent event) { - if (PROP_JAVADOC_DIR.equals(event.getPropertyName())) { - synchronized (this) { - result = null; - eventId++; - } - this.changeSupport.fireChange (); - } - } - } - if (isRootOwner(binaryRoot, "build.classes.dir") || isRootOwner (binaryRoot, "dist.jar")) { //NOI18N - return new R(); - } - return null; - } - - private boolean isRootOwner (URL binaryRoot, String binaryProperty) { - try { - if (FileUtil.getArchiveFile(binaryRoot) != null) { - binaryRoot = FileUtil.getArchiveFile(binaryRoot); - // XXX check whether this is really the root - } - String outDir = evaluator.getProperty(binaryProperty); - if (outDir != null) { - File f = helper.resolveFile (outDir); - URL url = f.toURI().toURL(); - if (!f.exists() && !f.getPath().toLowerCase().endsWith(".jar")) { // NOI18N - assert !url.toExternalForm().endsWith("/") : f; // NOI18N - url = new URL(url.toExternalForm() + "/"); // NOI18N - } - return url.equals(binaryRoot) || - binaryRoot.toExternalForm().startsWith(url.toExternalForm()); - } - } catch (MalformedURLException malformedURL) { - Exceptions.printStackTrace(malformedURL); - } - return false; - } - -// private URL getJavadoc(URL binaryRoot, String binaryProperty, String javadocProperty) { -// try { -// if (FileUtil.getArchiveFile(binaryRoot) != null) { -// binaryRoot = FileUtil.getArchiveFile(binaryRoot); -// } -// String outDir = evaluator.getProperty(binaryProperty); -// if (outDir != null) { -// File f = helper.resolveFile (outDir); -// URL url = f.toURI().toURL(); -// if (!f.exists() && !f.getPath().toLowerCase().endsWith(".jar")) { -// assert !url.toExternalForm().endsWith("/") : f; -// url = new URL(url.toExternalForm() + "/"); -// } -// if (url.equals(binaryRoot) || -// binaryRoot.toExternalForm().startsWith(url.toExternalForm())) { -// String javadocDir = evaluator.getProperty(javadocProperty); -// if (javadocDir != null) { -// f = helper.resolveFile(javadocDir); -// return f.toURI().toURL(); -// } -// } -// } -// } catch (MalformedURLException malformedURL) { -// ErrorManager.getDefault().notify(malformedURL); -// } -// return null; -// } - -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/SourceLevelQueryImpl.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/SourceLevelQueryImpl.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/SourceLevelQueryImpl.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.java.j2seproject.queries; - -import org.netbeans.modules.java.j2seproject.J2SEProjectUtil; -import org.netbeans.spi.java.queries.SourceLevelQueryImplementation; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.spi.project.support.ant.PropertyUtils; -import org.netbeans.spi.project.support.ant.EditableProperties; -import org.netbeans.api.java.platform.Specification; -import org.openide.filesystems.FileObject; - -/** - * Returns source level of project sources. - * @author David Konecny - */ -public class SourceLevelQueryImpl implements SourceLevelQueryImplementation { - - private final PropertyEvaluator evaluator; - - public SourceLevelQueryImpl(PropertyEvaluator evaluator) { - this.evaluator = evaluator; - } - - public String getSourceLevel(FileObject javaFile) { - final String activePlatform = evaluator.getProperty ("platform.active"); //NOI18N - if (J2SEProjectUtil.getActivePlatform(activePlatform) != null) { - String sl = evaluator.getProperty("javac.source"); //NOI18N - if (sl != null && sl.length() > 0) { - return sl; - } else { - return null; - } - } - else { - EditableProperties props = PropertyUtils.getGlobalProperties(); - String sl = (String) props.get("default.javac.source"); //NOI18N - if (sl != null && sl.length() > 0) { - return sl; - } else { - return null; - } - } - } - -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/UnitTestForSourceQueryImpl.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/UnitTestForSourceQueryImpl.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/UnitTestForSourceQueryImpl.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.java.j2seproject.queries; - -import java.net.URL; -import org.netbeans.api.project.FileOwnerQuery; -import org.netbeans.api.project.Project; -import org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation; -import org.netbeans.modules.java.j2seproject.SourceRoots; -import org.openide.filesystems.FileObject; - -public class UnitTestForSourceQueryImpl implements MultipleRootsUnitTestForSourceQueryImplementation { - - private final SourceRoots sourceRoots; - private final SourceRoots testRoots; - - public UnitTestForSourceQueryImpl(SourceRoots sourceRoots, SourceRoots testRoots) { - this.sourceRoots = sourceRoots; - this.testRoots = testRoots; - } - - public URL[] findUnitTests(FileObject source) { - return find(source, sourceRoots, testRoots); // NOI18N - } - - public URL[] findSources(FileObject unitTest) { - return find(unitTest, testRoots, sourceRoots); // NOI18N - } - - private URL[] find(FileObject file, SourceRoots from, SourceRoots to) { - Project p = FileOwnerQuery.getOwner(file); - if (p == null) { - return null; - } - FileObject[] fromRoots = from.getRoots(); - for (int i = 0; i < fromRoots.length; i++) { - if (fromRoots[i].equals(file)) { - return to.getRootURLs(); - } - } - return null; - } - -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/ActionFilterNode.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/ActionFilterNode.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/ActionFilterNode.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/ActionFilterNode.java @@ -65,10 +65,10 @@ import org.openide.util.lookup.ProxyLook import org.openide.util.lookup.ProxyLookup; import org.netbeans.api.java.queries.JavadocForBinaryQuery; import org.netbeans.api.project.ProjectManager; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.EditableProperties; import org.netbeans.spi.project.support.ant.PropertyUtils; -import org.netbeans.modules.java.j2seproject.UpdateHelper; import org.netbeans.spi.project.support.ant.ReferenceHelper; /** diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/J2SELogicalViewProvider.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/J2SELogicalViewProvider.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/J2SELogicalViewProvider.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/J2SELogicalViewProvider.java @@ -69,11 +69,11 @@ import org.netbeans.api.project.ProjectU import org.netbeans.api.project.ProjectUtils; import org.netbeans.api.project.SourceGroup; import org.netbeans.api.project.Sources; +import org.netbeans.modules.java.api.common.SourceRoots; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.modules.java.j2seproject.J2SEProjectUtil; import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; import org.netbeans.modules.java.j2seproject.J2SEProject; -import org.netbeans.modules.java.j2seproject.SourceRoots; -import org.netbeans.modules.java.j2seproject.UpdateHelper; import org.netbeans.spi.java.project.support.ui.BrokenReferencesSupport; import org.netbeans.spi.java.project.support.ui.PackageView; import org.netbeans.spi.project.ActionProvider; @@ -587,7 +587,7 @@ public class J2SELogicalViewProvider imp public void actionPerformed(ActionEvent e) { try { - helper.requestSave(); + helper.requestUpdate(); BrokenReferencesSupport.showCustomizer(helper.getAntProjectHelper(), resolver, getBreakableProperties(), new String[] {J2SEProjectProperties.JAVA_PLATFORM}); run(); } catch (IOException ioe) { diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNode.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNode.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNode.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNode.java @@ -91,6 +91,7 @@ import org.netbeans.api.project.ant.File import org.netbeans.api.project.ant.FileChooser; import org.netbeans.api.project.libraries.LibraryChooser; import org.netbeans.api.project.libraries.LibraryManager; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.modules.java.j2seproject.J2SEProject; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.EditableProperties; @@ -99,7 +100,6 @@ import org.netbeans.spi.project.support. import org.netbeans.spi.project.support.ant.ReferenceHelper; import org.netbeans.spi.java.project.support.ui.PackageView; import org.netbeans.spi.java.classpath.support.ClassPathSupport; -import org.netbeans.modules.java.j2seproject.UpdateHelper; import org.netbeans.modules.java.j2seproject.ui.customizer.AntArtifactChooser; import org.netbeans.spi.project.libraries.support.LibrariesSupport; import org.openide.util.Exceptions; diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNodeFactory.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNodeFactory.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNodeFactory.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNodeFactory.java @@ -47,16 +47,14 @@ import java.net.URI; import java.net.URI; import java.net.URL; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import javax.swing.Action; import javax.swing.SwingUtilities; -import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.netbeans.api.project.Project; +import org.netbeans.modules.java.api.common.SourceRoots; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.modules.java.j2seproject.J2SEProject; -import org.netbeans.modules.java.j2seproject.SourceRoots; -import org.netbeans.modules.java.j2seproject.UpdateHelper; import org.netbeans.modules.java.j2seproject.ui.customizer.CustomizerLibraries; import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; import org.netbeans.spi.project.support.ant.PropertyEvaluator; diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/ProjectNode.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/ProjectNode.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/ProjectNode.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/ProjectNode.java @@ -41,9 +41,7 @@ package org.netbeans.modules.java.j2seproject.ui; -import java.awt.Component; import java.awt.Image; -import java.awt.Panel; import java.io.IOException; import java.net.URI; import java.net.URL; @@ -80,11 +78,11 @@ import org.netbeans.api.project.ant.AntA import org.netbeans.api.project.ant.AntArtifact; import org.netbeans.api.project.ui.OpenProjects; import org.netbeans.api.java.queries.JavadocForBinaryQuery; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.spi.project.support.ant.EditableProperties; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.PropertyUtils; import org.netbeans.spi.project.support.ant.ReferenceHelper; -import org.netbeans.modules.java.j2seproject.UpdateHelper; diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerLibraries.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerLibraries.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerLibraries.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerLibraries.java @@ -54,6 +54,7 @@ import org.netbeans.api.java.platform.Ja import org.netbeans.api.java.platform.JavaPlatform; import org.netbeans.api.java.platform.PlatformsCustomizer; import org.netbeans.api.project.libraries.LibraryManager; +import org.netbeans.modules.java.api.common.ui.PlatformUiSupport; import org.netbeans.modules.java.j2seproject.classpath.ClassPathSupport; import org.netbeans.modules.java.j2seproject.ui.J2SELogicalViewProvider; import org.netbeans.modules.java.j2seproject.ui.wizards.PanelOptionsVisual; diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerProviderImpl.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerProviderImpl.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerProviderImpl.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerProviderImpl.java @@ -51,8 +51,8 @@ import java.util.Map; import java.util.Map; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectUtils; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.modules.java.j2seproject.J2SEProject; -import org.netbeans.modules.java.j2seproject.UpdateHelper; import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.ReferenceHelper; diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerRun.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerRun.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerRun.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerRun.java @@ -69,8 +69,8 @@ import javax.swing.event.DocumentListene import javax.swing.event.DocumentListener; import javax.swing.plaf.UIResource; import org.netbeans.api.project.Project; +import org.netbeans.modules.java.api.common.SourceRoots; import org.netbeans.modules.java.j2seproject.J2SEProject; -import org.netbeans.modules.java.j2seproject.SourceRoots; import org.netbeans.modules.java.j2seproject.api.J2SERunConfigProvider; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java @@ -67,10 +67,12 @@ import org.netbeans.api.queries.FileEnco import org.netbeans.api.queries.FileEncodingQuery; import org.netbeans.api.project.ProjectManager; import org.netbeans.api.project.ProjectUtils; +import org.netbeans.modules.java.api.common.SourceRoots; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; +import org.netbeans.modules.java.api.common.ui.PlatformUiSupport; import org.netbeans.modules.java.j2seproject.J2SEProject; +import org.netbeans.modules.java.j2seproject.J2SEProjectType; import org.netbeans.modules.java.j2seproject.J2SEProjectUtil; -import org.netbeans.modules.java.j2seproject.SourceRoots; -import org.netbeans.modules.java.j2seproject.UpdateHelper; import org.netbeans.modules.java.j2seproject.classpath.ClassPathSupport; import org.netbeans.spi.java.project.support.ui.IncludeExcludeVisualizer; import org.netbeans.spi.project.support.ant.AntProjectHelper; @@ -496,7 +498,7 @@ public class J2SEProjectProperties { projectProperties.setProperty( RUN_TEST_CLASSPATH, run_test_cp ); //Handle platform selection and javac.source javac.target properties - PlatformUiSupport.storePlatform (projectProperties, updateHelper,PLATFORM_MODEL.getSelectedItem(), JAVAC_SOURCE_MODEL.getSelectedItem()); + PlatformUiSupport.storePlatform (projectProperties, updateHelper, J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, PLATFORM_MODEL.getSelectedItem(), JAVAC_SOURCE_MODEL.getSelectedItem()); // Handle other special cases if ( NO_DEPENDENCIES_MODEL.isSelected() ) { // NOI18N diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SESourceRootsUi.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SESourceRootsUi.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SESourceRootsUi.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SESourceRootsUi.java @@ -47,7 +47,6 @@ import java.io.File; import java.io.File; import java.net.URI; import java.net.URL; -import java.util.ArrayList; import java.util.Iterator; import java.util.HashSet; import java.util.Set; @@ -66,18 +65,15 @@ import org.netbeans.api.project.SourceGr import org.netbeans.api.project.SourceGroup; import org.netbeans.api.project.Sources; import org.netbeans.modules.java.j2seproject.J2SEProject; -import org.netbeans.modules.java.j2seproject.ui.FoldersListSettings; import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectInformation; -import org.netbeans.modules.java.j2seproject.SourceRoots; +import org.netbeans.modules.java.api.common.SourceRoots; import org.openide.DialogDisplayer; import org.openide.DialogDescriptor; -import org.openide.NotifyDescriptor; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.NbBundle; -import org.openide.util.HelpCtx; /** Handles adding, removing, reordering of source roots. * diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/PlatformUiSupport.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/PlatformUiSupport.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/PlatformUiSupport.java +++ /dev/null @@ -1,670 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.java.j2seproject.ui.customizer; - -import java.awt.Component; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; -import java.util.logging.Logger; -import javax.swing.AbstractListModel; -import javax.swing.ComboBoxModel; -import javax.swing.JButton; -import javax.swing.JList; -import javax.swing.ListCellRenderer; -import javax.swing.event.ListDataEvent; -import javax.swing.event.ListDataListener; -import org.netbeans.api.java.platform.JavaPlatform; -import org.netbeans.api.java.platform.JavaPlatformManager; -import org.netbeans.api.java.platform.Specification; -import org.netbeans.modules.java.j2seproject.J2SEProjectType; -import org.netbeans.modules.java.j2seproject.UpdateHelper; -import org.netbeans.spi.project.support.ant.EditableProperties; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.awt.HtmlRenderer; -import org.openide.modules.SpecificationVersion; -import org.openide.util.NbBundle; -import org.openide.util.WeakListeners; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -/** - * Support class for {@link JavaPlatform} manipulation in j2seproject customizer. - * @author tzezula - */ -public class PlatformUiSupport { - - private static final SpecificationVersion JDK_5 = new SpecificationVersion ("1.5"); //NOI18N - private static final SpecificationVersion JDK_6 = new SpecificationVersion ("1.6"); //NOI18N - private static final Logger LOGGER = Logger.getLogger(PlatformUiSupport.class.getName()); - - private PlatformUiSupport() { - } - - /** - * Creates {@link ComboBoxModel} of J2SE platforms. - * The model listens on the {@link JavaPlatformManager} and update its - * state according to changes - * @param activePlatform the active project's platform - * @return {@link ComboBoxModel} - */ - public static ComboBoxModel createPlatformComboBoxModel (String activePlatform) { - return new PlatformComboBoxModel (activePlatform); - } - - - /** - * Creates a {@link ListCellRenderer} for rendering items of the {@link ComboBoxModel} - * created by the {@link PlatformUiSupport#createPlatformComboBoxModel} method. - * @return {@link ListCellRenderer} - */ - public static ListCellRenderer createPlatformListCellRenderer () { - return new PlatformListCellRenderer (); - } - - /** - * Stores active platform, javac.source and javac.target into the project's metadata - * @param props project's shared properties - * @param helper to read/update project.xml - * @param platformKey the PatformKey got from the platform model - * @param sourceLevel source level - */ - public static void storePlatform (EditableProperties props, UpdateHelper helper, Object platformKey, Object sourceLevelKey) { - assert platformKey instanceof PlatformKey; - PlatformKey pk = (PlatformKey) platformKey; - JavaPlatform platform = getPlatform(pk); - //null means active broken (unresolved) platform, no need to do anything - if (platform != null) { - SpecificationVersion jdk13 = new SpecificationVersion ("1.3"); //NOI18N - String platformAntName = (String) platform.getProperties().get("platform.ant.name"); //NOI18N - assert platformAntName != null; - props.put(J2SEProjectProperties.JAVA_PLATFORM, platformAntName); - Element root = helper.getPrimaryConfigurationData(true); - boolean defaultPlatform = pk.isDefaultPlatform(); - boolean changed = false; - NodeList explicitPlatformNodes = root.getElementsByTagNameNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"explicit-platform"); //NOI18N - if (defaultPlatform) { - if (explicitPlatformNodes.getLength()==1) { - root.removeChild(explicitPlatformNodes.item(0)); - changed = true; - } - } - else { - Element explicitPlatform; - switch (explicitPlatformNodes.getLength()) { - case 0: - explicitPlatform = root.getOwnerDocument().createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, "explicit-platform"); //NOI18N - NodeList sourceRootNodes = root.getElementsByTagNameNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N - assert sourceRootNodes.getLength() == 1 : "Broken project.xml file"; //NOI18N - root.insertBefore(explicitPlatform, sourceRootNodes.item(0)); - changed = true; - break; - case 1: - explicitPlatform = (Element)explicitPlatformNodes.item(0); - break; - default: - throw new AssertionError("Broken project.xml file"); //NOI18N - } - String explicitSourceAttrValue = explicitPlatform.getAttribute("explicit-source-supported"); //NOI18N - if (jdk13.compareTo(platform.getSpecification().getVersion())>=0 && - !"false".equals(explicitSourceAttrValue)) { //NOI18N - explicitPlatform.setAttribute("explicit-source-supported","false"); //NOI18N - changed = true; - } - else if (jdk13.compareTo(platform.getSpecification().getVersion())<0 && - !"true".equals(explicitSourceAttrValue)) { //NOI18N - explicitPlatform.setAttribute("explicit-source-supported","true"); //NOI18N - changed = true; - } - } - - SpecificationVersion sourceLevel; - if (sourceLevelKey == null) { - sourceLevel = platform.getSpecification().getVersion(); - } - else { - assert sourceLevelKey instanceof SourceLevelKey; - sourceLevel = ((SourceLevelKey)sourceLevelKey).getSourceLevel(); - } - String javacSource = sourceLevel.toString(); - String javacTarget = javacSource; - - //Issue #116490 - // Customizer value | -source | -targer - // JDK 1.2 1.2 1.1 - // JDK 1.3 1.3 1.1 - // JDK 1.4 1.4 1.4 - // JDK 5 1.5 1.5 - // JDK 6 1.5 1.6 - // JDK 7 1.7 1.7 - should bring a new language features - if (jdk13.compareTo(sourceLevel)>=0) { - javacTarget = "1.1"; //NOI18N - } - else if (JDK_6.equals(sourceLevel)) { - javacSource = JDK_5.toString(); - } - - if (!javacSource.equals(props.getProperty(J2SEProjectProperties.JAVAC_SOURCE))) { - props.setProperty (J2SEProjectProperties.JAVAC_SOURCE, javacSource); - } - if (!javacTarget.equals(props.getProperty(J2SEProjectProperties.JAVAC_TARGET))) { - props.setProperty (J2SEProjectProperties.JAVAC_TARGET, javacTarget); - } - - if (changed) { - helper.putPrimaryConfigurationData(root, true); - } - } - } - - - /** - * Returns a {@link JavaPlatform} for an item obtained from the ComboBoxModel created by - * the {@link PlatformUiSupport#createComboBoxModel} method - * @param platformKey an item obtained from ComboBoxModel created by {@link PlatformUiSupport#createComboBoxModel} - * @return JavaPlatform or null in case when platform is broken - * @exception {@link IllegalArgumentException} is thrown in case when parameter in not an object created by - * platform combobox model. - */ - public static JavaPlatform getPlatform (Object platformKey) { - if (platformKey instanceof PlatformKey) { - return getPlatform ((PlatformKey)platformKey); - } - else { - throw new IllegalArgumentException (); - } - } - - /** - * Creates {@link ComboBoxModel} of source levels for active platform. - * The model listens on the platform's {@link ComboBoxModel} and update its - * state according to changes - * @param platformComboBoxModel the platform's model used for listenning - * @param initialValue initial source level value - * @return {@link ComboBoxModel} of {@link SpecificationVersion} - */ - public static ComboBoxModel createSourceLevelComboBoxModel (ComboBoxModel platformComboBoxModel, String initialSourceLevel, String initinalTargetLevel) { - return new SourceLevelComboBoxModel (platformComboBoxModel, initialSourceLevel, initinalTargetLevel); - } - - - public static ListCellRenderer createSourceLevelListCellRenderer () { - return new SourceLevelListCellRenderer (); - } - - - private static JavaPlatform getPlatform (PlatformKey platformKey) { - return platformKey.platform; - } - - - /** - * This class represents a JavaPlatform in the {@link ListModel} - * created by the {@link PlatformUiSupport#createPlatformComboBoxModel} - * method. - */ - private static class PlatformKey implements Comparable { - - private String name; - private JavaPlatform platform; - - /** - * Creates a PlatformKey for a broken platform - * @param name the ant name of the broken platform - */ - public PlatformKey (String name) { - assert name != null; - this.name = name; - } - - /** - * Creates a PlatformKey for a platform - * @param platform the {@link JavaPlatform} - */ - public PlatformKey (JavaPlatform platform) { - assert platform != null; - this.platform = platform; - } - - public int compareTo(Object o) { - return this.getDisplayName().compareTo(((PlatformKey)o).getDisplayName()); - } - - public boolean equals (Object other) { - if (other instanceof PlatformKey) { - PlatformKey otherKey = (PlatformKey)other; - return (this.platform == null ? otherKey.platform == null : this.platform.equals(otherKey.platform)) && - otherKey.getDisplayName().equals (this.getDisplayName()); - } - else { - return false; - } - } - - public int hashCode () { - return getDisplayName ().hashCode (); - } - - public String toString () { - return getDisplayName (); - } - - public synchronized String getDisplayName () { - if (this.name == null) { - this.name = this.platform.getDisplayName(); - } - return this.name; - } - - public boolean isDefaultPlatform () { - if (this.platform == null) { - return false; - } - return this.platform.equals(JavaPlatformManager.getDefault().getDefaultPlatform()); - } - - public boolean isBroken () { - return this.platform == null; - } - - } - - private static final class SourceLevelKey implements Comparable { - - final SpecificationVersion sourceLevel; - final boolean broken; - - public SourceLevelKey (final SpecificationVersion sourceLevel) { - this (sourceLevel, false); - } - - public SourceLevelKey (final SpecificationVersion sourceLevel, final boolean broken) { - assert sourceLevel != null : "Source level cannot be null"; //NOI18N - this.sourceLevel = sourceLevel; - this.broken = broken; - } - - public SpecificationVersion getSourceLevel () { - return this.sourceLevel; - } - - public boolean isBroken () { - return this.broken; - } - - public int compareTo (final Object other) { - assert other instanceof SourceLevelKey : "Illegal argument of SourceLevelKey.compareTo()"; //NOI18N - SourceLevelKey otherKey = (SourceLevelKey) other; - return this.sourceLevel.compareTo(otherKey.sourceLevel); - } - - public @Override boolean equals (final Object other) { - return (other instanceof SourceLevelKey) && - ((SourceLevelKey)other).sourceLevel.equals(this.sourceLevel); - } - - public @Override int hashCode () { - return this.sourceLevel.hashCode(); - } - - public @Override String toString () { - StringBuffer buffer = new StringBuffer (); - if (this.broken) { - buffer.append("Broken: "); //NOI18N - } - buffer.append(this.sourceLevel.toString()); - return buffer.toString(); - } - - public String getDisplayName () { - String _tmp = sourceLevel.toString(); - if (JDK_5.compareTo(sourceLevel)<=0) { - _tmp = _tmp.replaceFirst("^1\\.([5-9]|\\d\\d+)$", "$1"); //NOI18N - } - return NbBundle.getMessage(PlatformUiSupport.class, "LBL_JDK",_tmp); - } - - } - - private static class PlatformComboBoxModel extends AbstractListModel implements ComboBoxModel, PropertyChangeListener { - - private JavaPlatformManager pm; - private PlatformKey[] platformNamesCache; - private String initialPlatform; - private PlatformKey selectedPlatform; - - public PlatformComboBoxModel (String initialPlatform) { - this.pm = JavaPlatformManager.getDefault(); - this.pm.addPropertyChangeListener(WeakListeners.propertyChange(this, this.pm)); - this.initialPlatform = initialPlatform; - } - - public int getSize () { - PlatformKey[] platformNames = getPlatformNames (); - return platformNames.length; - } - - public Object getElementAt (int index) { - PlatformKey[] platformNames = getPlatformNames (); - assert index >=0 && index< platformNames.length; - return platformNames[index]; - } - - public Object getSelectedItem () { - this.getPlatformNames(); //Force setting of selectedPlatform if it is not alredy done - return this.selectedPlatform; - } - - public void setSelectedItem (Object obj) { - this.selectedPlatform = (PlatformKey) obj; - this.fireContentsChanged(this, -1, -1); - } - - public void propertyChange (PropertyChangeEvent event) { - if (JavaPlatformManager.PROP_INSTALLED_PLATFORMS.equals(event.getPropertyName())) { - synchronized (this) { - this.platformNamesCache = null; - } - this.fireContentsChanged(this, -1, -1); - } - } - - private synchronized PlatformKey[] getPlatformNames () { - if (this.platformNamesCache == null) { - JavaPlatform[] platforms = pm.getPlatforms (null, new Specification("j2se",null)); //NOI18N - JavaPlatform defaultPlatform = pm.getDefaultPlatform (); - Set/**/ orderedNames = new TreeSet (); - boolean activeFound = false; - for (int i=0; i< platforms.length; i++) { - if (platforms[i].getInstallFolders().size()>0) { - PlatformKey pk = new PlatformKey(platforms[i]); - orderedNames.add (pk); - if (!activeFound && initialPlatform != null) { - String antName = (String) platforms[i].getProperties().get("platform.ant.name"); //NOI18N - if (initialPlatform.equals(antName)) { - if (this.selectedPlatform == null) { - this.selectedPlatform = pk; - initialPlatform = null; - } - activeFound = true; - } - } - } - } - if (!activeFound) { - if (initialPlatform == null) { - if (this.selectedPlatform == null || !orderedNames.contains(this.selectedPlatform)) { - this.selectedPlatform = new PlatformKey (JavaPlatformManager.getDefault().getDefaultPlatform()); - } - } - else { - PlatformKey pk = new PlatformKey (this.initialPlatform); - orderedNames.add (pk); - if (this.selectedPlatform == null) { - this.selectedPlatform = pk; - } - } - } - this.platformNamesCache = (PlatformKey[]) orderedNames.toArray(new PlatformKey[orderedNames.size()]); - } - return this.platformNamesCache; - } - - } - - private static class PlatformListCellRenderer implements ListCellRenderer { - - private ListCellRenderer delegate; - - public PlatformListCellRenderer () { - this.delegate = HtmlRenderer.createRenderer (); - } - - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - String name; - if (value == null) { - name = ""; //NOI18N - } - else { - assert value instanceof PlatformKey : "Wrong model"; //NOI18N - PlatformKey key = (PlatformKey) value; - if (key.isBroken()) { - name = "" + //NOI18N - NbBundle.getMessage (PlatformUiSupport.class,"TXT_BrokenPlatformFmt", key.getDisplayName()); - } - else { - name = key.getDisplayName(); - } - } - return this.delegate.getListCellRendererComponent(list, name, index, isSelected, cellHasFocus); - } - } - - private static class SourceLevelComboBoxModel extends AbstractListModel implements ComboBoxModel, ListDataListener { - - private static final String VERSION_PREFIX = "1."; //The version prefix - private static final int INITIAL_VERSION_MINOR = 2; //1.2 - - private SpecificationVersion selectedSourceLevel; - private SpecificationVersion originalSourceLevel; - private SourceLevelKey[] sourceLevelCache; - private final ComboBoxModel platformComboBoxModel; - private PlatformKey activePlatform; - - public SourceLevelComboBoxModel (ComboBoxModel platformComboBoxModel, String initialSourceLevel, String initialTargetLevel) { - this.platformComboBoxModel = platformComboBoxModel; - this.activePlatform = (PlatformKey) this.platformComboBoxModel.getSelectedItem(); - this.platformComboBoxModel.addListDataListener (this); - if (initialSourceLevel != null && initialSourceLevel.length() > 0) { - try { - this.originalSourceLevel = new SpecificationVersion (initialSourceLevel); - } catch (NumberFormatException nfe) { - //If the javac.source has invalid value, do not preselect and log it - LOGGER.warning("Invalid javac.source: "+initialSourceLevel); //NO18N - } - } - if (initialTargetLevel != null && initialTargetLevel.length() > 0) { - try { - SpecificationVersion originalTargetLevel = new SpecificationVersion (initialTargetLevel); - if (this.originalSourceLevel == null || this.originalSourceLevel.compareTo(originalTargetLevel)<0) { - this.originalSourceLevel = originalTargetLevel; - } - } catch (NumberFormatException nfe) { - //If the javac.target has invalid value, do not preselect and log it - LOGGER.warning("Invalid javac.target: "+initialTargetLevel); //NOI18N - } - } - this.selectedSourceLevel = this.originalSourceLevel; - } - - public int getSize () { - SourceLevelKey[] sLevels = getSourceLevels (); - return sLevels.length; - } - - public Object getElementAt (int index) { - SourceLevelKey[] sLevels = getSourceLevels (); - assert index >=0 && index< sLevels.length; - return sLevels[index]; - } - - public Object getSelectedItem () { - SourceLevelKey[] keys = getSourceLevels (); - for (int i=0; i0 && - !shouldChangePlatform (selectedSourceLevel, version)) { - //Restore original - this.platformComboBoxModel.setSelectedItem(this.activePlatform); - return; - } - else { - this.originalSourceLevel = null; - } - } - this.activePlatform = selectedPlatform; - resetCache (); - } - - private void resetCache () { - synchronized (this) { - this.sourceLevelCache = null; - } - this.fireContentsChanged(this, -1, -1); - } - - private SourceLevelKey[] getSourceLevels () { - if (this.sourceLevelCache == null) { - PlatformKey selectedPlatform = (PlatformKey) this.platformComboBoxModel.getSelectedItem(); - JavaPlatform platform = getPlatform(selectedPlatform); - List/**/ sLevels = new ArrayList (); - //If platform == null broken platform, the source level range is unknown - //The source level combo box should be empty and disabled - boolean selSourceLevelValid = false; - if (platform != null) { - SpecificationVersion version = platform.getSpecification().getVersion(); - int index = INITIAL_VERSION_MINOR; - SpecificationVersion template = new SpecificationVersion (VERSION_PREFIX + Integer.toString (index++)); - boolean origSourceLevelValid = false; - - while (template.compareTo(version)<=0) { - if (template.equals(this.originalSourceLevel)) { - origSourceLevelValid = true; - } - if (template.equals(this.selectedSourceLevel)) { - selSourceLevelValid = true; - } - sLevels.add (new SourceLevelKey (template)); - template = new SpecificationVersion (VERSION_PREFIX + Integer.toString (index++)); - } - if (this.originalSourceLevel != null && !origSourceLevelValid) { - if (originalSourceLevel.equals(this.selectedSourceLevel)) { - selSourceLevelValid = true; - } - sLevels.add (new SourceLevelKey(this.originalSourceLevel,true)); - } - } - this.sourceLevelCache = (SourceLevelKey[]) sLevels.toArray(new SourceLevelKey[sLevels.size()]); - if (!selSourceLevelValid) { - this.selectedSourceLevel = this.sourceLevelCache.length == 0 ? - null : this.sourceLevelCache[this.sourceLevelCache.length-1].getSourceLevel(); - } - } - return this.sourceLevelCache; - } - - private static boolean shouldChangePlatform (SpecificationVersion selectedSourceLevel, SpecificationVersion platformSourceLevel) { - JButton changeOption = new JButton (NbBundle.getMessage(PlatformUiSupport.class, "CTL_ChangePlatform")); - changeOption.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PlatformUiSupport.class, "AD_ChangePlatform")); - String message = MessageFormat.format (NbBundle.getMessage(PlatformUiSupport.class,"TXT_ChangePlatform"),new Object[] { - selectedSourceLevel.toString(), - platformSourceLevel.toString(), - }); - return DialogDisplayer.getDefault().notify( - new NotifyDescriptor (message, - NbBundle.getMessage(PlatformUiSupport.class,"TXT_ChangePlatformTitle"), - NotifyDescriptor.DEFAULT_OPTION, - NotifyDescriptor.WARNING_MESSAGE, - new Object[] { - changeOption, - NotifyDescriptor.CANCEL_OPTION - }, - changeOption)) == changeOption; - } - } - - private static class SourceLevelListCellRenderer implements ListCellRenderer { - - ListCellRenderer delegate; - - public SourceLevelListCellRenderer () { - this.delegate = HtmlRenderer.createRenderer(); - } - - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - String message; - if (value == null) { - message = ""; //NOI18N - } - else { - assert value instanceof SourceLevelKey; - SourceLevelKey key = (SourceLevelKey) value; - if (key.isBroken()) { - message = "" + //NOI18N - NbBundle.getMessage(PlatformUiSupport.class,"TXT_InvalidSourceLevel",key.getDisplayName()); - } - else { - message = key.getDisplayName(); - } - } - return this.delegate.getListCellRendererComponent(list, message, index, isSelected, cellHasFocus); - } - } - -} diff --git a/java.j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/SourceRootsTest.java b/java.j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/SourceRootsTest.java --- a/java.j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/SourceRootsTest.java +++ b/java.j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/SourceRootsTest.java @@ -55,6 +55,7 @@ import org.netbeans.api.project.ProjectM import org.netbeans.api.project.ProjectManager; import org.netbeans.api.project.Project; import org.netbeans.api.project.TestUtil; +import org.netbeans.modules.java.api.common.SourceRoots; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.EditableProperties; import org.w3c.dom.Element; diff --git a/nbbuild/cluster.properties b/nbbuild/cluster.properties --- a/nbbuild/cluster.properties +++ b/nbbuild/cluster.properties @@ -387,6 +387,7 @@ nb.cluster.java=\ java.platform,\ java.preprocessorbridge,\ java.project,\ + java.commonapi,\ java.source,\ java.sourceui,\ javadoc,\ diff --git a/nbbuild/javadoctools/links.xml b/nbbuild/javadoctools/links.xml --- a/nbbuild/javadoctools/links.xml +++ b/nbbuild/javadoctools/links.xml @@ -163,3 +163,4 @@ made subject to such option by the copyr + diff --git a/nbbuild/javadoctools/properties.xml b/nbbuild/javadoctools/properties.xml --- a/nbbuild/javadoctools/properties.xml +++ b/nbbuild/javadoctools/properties.xml @@ -161,3 +161,4 @@ made subject to such option by the copyr + diff --git a/nbbuild/javadoctools/replaces.xml b/nbbuild/javadoctools/replaces.xml --- a/nbbuild/javadoctools/replaces.xml +++ b/nbbuild/javadoctools/replaces.xml @@ -161,3 +161,4 @@ made subject to such option by the copyr + diff --git a/web.project/nbproject/project.xml b/web.project/nbproject/project.xml --- a/web.project/nbproject/project.xml +++ b/web.project/nbproject/project.xml @@ -200,6 +200,15 @@ made subject to such option by the copyr 4 1.29 + + + + org.netbeans.modules.java.api.common + + + + 0-1 + 1.0 diff --git a/web.project/src/org/netbeans/modules/web/project/ProjectWebModule.java b/web.project/src/org/netbeans/modules/web/project/ProjectWebModule.java --- a/web.project/src/org/netbeans/modules/web/project/ProjectWebModule.java +++ b/web.project/src/org/netbeans/modules/web/project/ProjectWebModule.java @@ -82,6 +82,7 @@ import org.netbeans.modules.j2ee.dd.spi. import org.netbeans.modules.j2ee.dd.spi.web.WebAppMetadataModelFactory; import org.netbeans.modules.j2ee.dd.spi.webservices.WebservicesMetadataModelFactory; import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.modules.websvc.spi.webservices.WebServicesConstants; /** A web module implementation on top of project. diff --git a/web.project/src/org/netbeans/modules/web/project/SourceRoots.java b/web.project/src/org/netbeans/modules/web/project/SourceRoots.java deleted file mode 100644 --- a/web.project/src/org/netbeans/modules/web/project/SourceRoots.java +++ /dev/null @@ -1,438 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.web.project; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URI; -import java.util.Arrays; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.HashMap; -import java.text.MessageFormat; - -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.util.NbBundle; -import org.openide.util.WeakListeners; -import org.openide.util.Mutex; - -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; -import org.w3c.dom.Document; - -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.AntProjectEvent; -import org.netbeans.spi.project.support.ant.AntProjectListener; -import org.netbeans.spi.project.support.ant.EditableProperties; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.spi.project.support.ant.ReferenceHelper; -import org.netbeans.api.project.ProjectManager; -import org.netbeans.api.java.project.JavaProjectConstants; -import org.openide.util.Exceptions; - -/** - * This class represents a project source roots. It is used to obtain roots as Ant properties, FileObject's - * or URLs. - * @author Tomas Zezula - */ -public final class SourceRoots { - - public static final String PROP_ROOT_PROPERTIES = "rootProperties"; //NOI18N - public static final String PROP_ROOTS = "roots"; //NOI18N - - public static final String DEFAULT_SOURCE_LABEL = NbBundle.getMessage(SourceRoots.class, "NAME_src.dir"); - public static final String DEFAULT_TEST_LABEL = NbBundle.getMessage(SourceRoots.class, "NAME_test.src.dir"); - - private final UpdateHelper helper; - private final PropertyEvaluator evaluator; - private final ReferenceHelper refHelper; - private final String elementName; - private final String newRootNameTemplate; - private List/**/ sourceRootProperties; - private List/**/ sourceRootNames; - private List/**/ sourceRoots; - private List/**/ sourceRootURLs; - private final PropertyChangeSupport support; - private final ProjectMetadataListener listener; - private final boolean isTest; - private final File projectDir; - - /** - * Creates new SourceRoots - * @param helper - * @param evaluator - * @param elementName the name of XML element under which are declared the roots - * @param newRootNameTemplate template for new property name of source root - */ - SourceRoots (UpdateHelper helper, PropertyEvaluator evaluator, ReferenceHelper refHelper, String elementName, boolean isTest, String newRootNameTemplate) { - assert helper != null && evaluator != null && refHelper != null && elementName != null && newRootNameTemplate != null; - this.helper = helper; - this.evaluator = evaluator; - this.refHelper = refHelper; - this.elementName = elementName; - this.isTest = isTest; - this.newRootNameTemplate = newRootNameTemplate; - this.projectDir = FileUtil.toFile(this.helper.getAntProjectHelper().getProjectDirectory()); - this.support = new PropertyChangeSupport(this); - this.listener = new ProjectMetadataListener(); - this.evaluator.addPropertyChangeListener (WeakListeners.propertyChange(this.listener,this.evaluator)); - this.helper.getAntProjectHelper().addAntProjectListener ((AntProjectListener)WeakListeners.create(AntProjectListener.class, this.listener,this.helper)); - } - - - /** - * Returns the display names of soruce roots - * The returned array has the same length as an array returned by the getRootProperties. - * It may contain empty strings but not null. - * @return an array of String - */ - public String[] getRootNames () { - return (String[]) ProjectManager.mutex().readAccess(new Mutex.Action() { - public Object run() { - synchronized (SourceRoots.this) { - if (sourceRootNames == null) { - readProjectMetadata(); - } - } - return sourceRootNames.toArray (new String[sourceRootNames.size()]); - } - }); - } - - /** - * Returns names of Ant properties in the project.properties file holding the source roots. - * @return an array of String - */ - public String[] getRootProperties () { - return (String[]) ProjectManager.mutex().readAccess(new Mutex.Action() { - public Object run() { - synchronized (SourceRoots.this) { - if (sourceRootProperties == null) { - readProjectMetadata(); - } - } - return sourceRootProperties.toArray (new String[sourceRootProperties.size()]); - } - }); - } - - /** - * Returns the source roots - * @return an array of FileObject - */ - public FileObject[] getRoots () { - return (FileObject[]) ProjectManager.mutex().readAccess(new Mutex.Action () { - public Object run () { - synchronized (this) { - //Local caching - if (sourceRoots == null) { - String[] srcProps = getRootProperties(); - List result = new ArrayList(); - for (int i = 0; i0) { - Element root = (Element) rootsNodes.item(0); - ownerElement.removeChild(root); - } - //Remove all unused root properties - List newRoots = Arrays.asList(roots); - Map propsToRemove = new HashMap (oldRoots2props); - propsToRemove.keySet().removeAll(newRoots); - EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - for (Iterator it = propsToRemove.values().iterator(); it.hasNext();) { - String propName = (String) it.next (); - props.remove(propName); - } - helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,props); - //Add the new roots - Document doc = ownerElement.getOwnerDocument(); - oldRoots2props.keySet().retainAll(newRoots); - for (Iterator it = newRoots.iterator(); it.hasNext();) { - URL newRoot = (URL) it.next (); - String rootName = (String) oldRoots2props.get (newRoot); - if (rootName == null) { - //Root is new generate property for it - props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - String[] names = newRoot.getPath().split("/"); //NOI18N - rootName = MessageFormat.format(newRootNameTemplate, new Object[]{names[names.length-1],""}); //NOI18N - int rootIndex = 1; - while (props.containsKey(rootName)) { - rootIndex++; - rootName = MessageFormat.format(newRootNameTemplate,new Object[]{names[names.length-1], Integer.valueOf(rootIndex)}); - } - File f = FileUtil.normalizeFile(new File(URI.create(newRoot.toExternalForm()))); - File projDir = FileUtil.toFile(helper.getAntProjectHelper().getProjectDirectory()); - String path = f.getAbsolutePath(); - String prjPath = projDir.getAbsolutePath()+File.separatorChar; - if (path.startsWith(prjPath)) { - path = path.substring(prjPath.length()); - } - else { - path = refHelper.createForeignFileReference(f, JavaProjectConstants.SOURCES_TYPE_JAVA); - props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - } - props.put(rootName,path); - helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,props); - } - Element newRootNode = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, "root"); //NOI18N - newRootNode.setAttribute("id",rootName); //NOI18N - String label = (String) newRoots2lab.get (newRoot); - if (label != null && label.length()>0 && !label.equals (getRootDisplayName(null,rootName))) { //NOI18N - newRootNode.setAttribute("name",label); //NOI18N - } - ownerElement.appendChild (newRootNode); - } - helper.putPrimaryConfigurationData(cfgEl,true); - return null; - } - } - ); - } - - /** - * Translates root name into display name of source/test root - * @param rootName the name of root got from {@link SourceRoots#getRootNames} - * @param propName the name of property the root is stored in - * @return the label to be displayed - */ - public String getRootDisplayName (String rootName, String propName) { - if (rootName == null || rootName.length() ==0) { - //If the prop is src.dir use the default name - if (isTest && "test.src.dir".equals(propName)) { //NOI18N - rootName = DEFAULT_TEST_LABEL; - } - else if (!isTest && "src.dir".equals(propName)) { //NOI18N - rootName = DEFAULT_SOURCE_LABEL; - } - else { - //If the name is not given, it should be either a relative path in the project dir - //or absolute path when the root is not under the project dir - String propValue = evaluator.getProperty(propName); - File sourceRoot = propValue == null ? null : helper.getAntProjectHelper().resolveFile(propValue); - rootName = createInitialDisplayName(sourceRoot); - } - } - return rootName; - } - - public String createInitialDisplayName (File sourceRoot) { - String rootName; - if (sourceRoot != null) { - String srPath = sourceRoot.getAbsolutePath(); - String pdPath = projectDir.getAbsolutePath() + File.separatorChar; - if (srPath.startsWith(pdPath)) { - rootName = srPath.substring(pdPath.length()); - } - else { - rootName = sourceRoot.getAbsolutePath(); - } - } - else { - rootName = isTest ? DEFAULT_TEST_LABEL : DEFAULT_SOURCE_LABEL; - } - return rootName; - } - - private void resetCache (boolean isXMLChange, String propName) { - boolean fire = false; - synchronized (this) { - //In case of change reset local cache - if (isXMLChange) { - this.sourceRootProperties = null; - this.sourceRootNames = null; - this.sourceRoots = null; - this.sourceRootURLs = null; - fire = true; - } else if (propName == null || (sourceRootProperties != null && sourceRootProperties.contains(propName))) { - this.sourceRoots = null; - this.sourceRootURLs = null; - fire = true; - } - } - if (fire) { - if (isXMLChange) { - this.support.firePropertyChange (PROP_ROOT_PROPERTIES,null,null); - } - this.support.firePropertyChange (PROP_ROOTS,null,null); - } - } - - private void readProjectMetadata () { - Element cfgEl = helper.getPrimaryConfigurationData(true); - NodeList nl = cfgEl.getElementsByTagNameNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, elementName); - assert nl.getLength() == 0 || nl.getLength() == 1 : "Illegal project.xml"; //NOI18N - List rootProps = new ArrayList (); - List rootNames = new ArrayList (); - // It can be 0 in the case when the project is created by WebProjectGenerator and not yet customized - if (nl.getLength()==1) { - NodeList roots = ((Element)nl.item(0)).getElementsByTagNameNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, "root"); //NOI18N - for (int i=0; i 0 : "Illegal project.xml"; - rootProps.add(value); - value = root.getAttribute("name"); //NOI18N - rootNames.add (value); - } - } - this.sourceRootProperties = Collections.unmodifiableList(rootProps); - this.sourceRootNames = Collections.unmodifiableList(rootNames); - } - - private class ProjectMetadataListener implements PropertyChangeListener,AntProjectListener { - - public void propertyChange(PropertyChangeEvent evt) { - resetCache (false,evt.getPropertyName()); - } - - public void configurationXmlChanged(AntProjectEvent ev) { - resetCache (true,null); - } - - public void propertiesChanged(AntProjectEvent ev) { - //Handled by propertyChange - } - } - - public boolean isTest() { - return isTest; - } -} diff --git a/web.project/src/org/netbeans/modules/web/project/UpdateHelper.java b/web.project/src/org/netbeans/modules/web/project/UpdateHelper.java deleted file mode 100644 --- a/web.project/src/org/netbeans/modules/web/project/UpdateHelper.java +++ /dev/null @@ -1,563 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.web.project; - -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import javax.swing.JButton; -import org.netbeans.api.project.libraries.LibraryManager; -import org.netbeans.modules.web.project.api.WebProjectUtilities; -import org.netbeans.modules.web.project.classpath.ClassPathSupport; -import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties; -import org.netbeans.spi.project.support.ant.ReferenceHelper; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.filesystems.Repository; -import org.w3c.dom.Comment; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.util.NbBundle; -import org.openide.util.Mutex; -import org.netbeans.api.project.Project; -import org.netbeans.api.project.ProjectManager; -import org.netbeans.spi.project.AuxiliaryConfiguration; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.EditableProperties; -import org.openide.filesystems.URLMapper; -import org.openide.util.Exceptions; - - -/** - * Proxy for the AntProjectHelper which defers the update of the project metadata - * to explicit user action. Currently it is hard coded for update from - * "http://www.netbeans.org/ns/web-project/1" to "http://www.netbeans.org/ns/web-project/2". - * In future it should define plugable SPI. - */ -public class UpdateHelper { - - private static final boolean TRANSPARENT_UPDATE = Boolean.getBoolean("webproject.transparentUpdate"); //NOI18N - private static final String BUILD_NUMBER = System.getProperty("netbeans.buildnumber"); // NOI18N - - private final Project project; - private final AntProjectHelper helper; - private final AuxiliaryConfiguration cfg; - private final Notifier notifier; - private boolean alreadyAskedInWriteAccess; - private Boolean isCurrent; - private EditableProperties cachedProperties; - private Element cachedElement; - private static final String TAG_MINIMUM_ANT_VERSION = "minimum-ant-version"; // NOI18N - private static final String TAG_FILE = "file"; //NOI18N - private static final String TAG_LIBRARY = "library"; //NOI18N - private static final String ATTR_FILES = "files"; //NOI18N - private static final String ATTR_DIRS = "dirs"; //NOI18N - - /** - * Creates new UpdateHelper - * @param project - * @param helper AntProjectHelper - * @param cfg AuxiliaryConfiguration - * @param notifier used to ask user about project update - */ - UpdateHelper (Project project, AntProjectHelper helper, AuxiliaryConfiguration cfg, Notifier notifier) { - assert project != null && helper != null && cfg != null && notifier != null; - this.project = project; - this.helper = helper; - this.cfg = cfg; - this.notifier = notifier; - } - - /** - * Returns the AntProjectHelper.getProperties(), {@link AntProjectHelper#getProperties(String)} - * @param path a relative URI in the project directory. - * @return a set of properties - */ - public EditableProperties getProperties (final String path) { - //Properties are the same in both webproject/1 and webproject/2 - return (EditableProperties) ProjectManager.mutex().readAccess(new Mutex.Action (){ - public Object run() { - if (!isCurrent() && AntProjectHelper.PROJECT_PROPERTIES_PATH.equals(path)) { //Only project properties were changed - return getUpdatedProjectProperties (); - } - else { - return helper.getProperties(path); - } - } - }); - } - - /** - * In the case that the project is of current version or the properties are not {@link AntProjectHelper#PROJECT_PROPERTIES_PATH} - * it calls AntProjectHelper.putProperties(), {@link AntProjectHelper#putProperties(String, EditableProperties)} - * otherwise it asks user to updata project. If the user agrees with the project update, it does the update and calls - * AntProjectHelper.putProperties(). - * @param path a relative URI in the project directory. - * @param props a set of properties - */ - public void putProperties (final String path, final EditableProperties props) { - ProjectManager.mutex().writeAccess(new Runnable() { - public void run() { - if (isCurrent() || !AntProjectHelper.PROJECT_PROPERTIES_PATH.equals(path)) { //Only project props should cause update - helper.putProperties(path,props); - } else if (canUpdate()) { - try { - saveUpdate(props); - helper.putProperties(path,props); - } catch (IOException ioe) { - Exceptions.printStackTrace(ioe); - } - } - } - }); - } - - /** - * In the case that the project is of current version or shared is false it delegates to - * AntProjectHelper.getPrimaryConfigurationData(), {@link AntProjectHelper#getPrimaryConfigurationData(boolean)}. - * Otherwise it creates an in memory update of shared configuration data and returns it. - * @param shared if true, refers to project.xml, else refers to - * private.xml - * @return the configuration data that is available - */ - public Element getPrimaryConfigurationData (final boolean shared) { - return (Element) ProjectManager.mutex().readAccess(new Mutex.Action (){ - public Object run() { - if (!shared || isCurrent()) { //Only shared props should cause update - return helper.getPrimaryConfigurationData(shared); - } - else { - return getUpdatedSharedConfigurationData (); - } - } - }); - } - - /** - * In the case that the project is of current version or shared is false it calls AntProjectHelper.putPrimaryConfigurationData(), - * {@link AntProjectHelper#putPrimaryConfigurationData(Element, boolean)}. - * Otherwise it asks user to update the project. If the user agrees with the project update, it does the update and calls - * AntProjectHelper.PrimaryConfigurationData(). - * @param element the configuration data - * @param shared if true, refers to project.xml, else refers to - * private.xml - */ - public void putPrimaryConfigurationData (final Element element, final boolean shared) { - ProjectManager.mutex().writeAccess(new Runnable() { - public void run() { - if (!shared || isCurrent()) { - helper.putPrimaryConfigurationData(element, shared); - } else if (canUpdate()) { - try { - saveUpdate(null); - helper.putPrimaryConfigurationData(element, shared); - } catch (IOException ioe) { - Exceptions.printStackTrace(ioe); - } - } - } - }); - } - - /** - * Returns an AntProjectHelper. The helper may not be used for accessing/storing project metadata. - * For project metadata manipulation the UpdateHelper must be used. - * @return AntProjectHelper - */ - public AntProjectHelper getAntProjectHelper () { - return this.helper; - } - - /** - * Request an saving of update. If the project is not of current version the user will be asked to update the project. - * If the user agrees with an update the project is updated. - * @return true if the metadata are of current version or updated - */ - public boolean requestSave () throws IOException{ - if (isCurrent()) { - return true; - } - if (!canUpdate()) { - return false; - } - saveUpdate (null); - return true; - } - - /** - * Returns true if the project is of current version. - * @return true if the project is of current version, otherwise false. - */ - public synchronized boolean isCurrent () { - if (this.isCurrent == null) { - this.isCurrent = this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/web-project/1",true) == null //NOI18N - && this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/web-project/2",true) == null? //NOI18N - Boolean.TRUE : Boolean.FALSE; - } - return isCurrent.booleanValue(); - } - - private boolean canUpdate () { - if (TRANSPARENT_UPDATE) { - return true; - } - //Ask just once under a single write access - if (alreadyAskedInWriteAccess) { - return false; - } - else { - boolean canUpdate = this.notifier.canUpdate(); - if (!canUpdate) { - alreadyAskedInWriteAccess = true; - ProjectManager.mutex().postReadRequest(new Runnable() { - public void run() { - alreadyAskedInWriteAccess = false; - } - }); - } - return canUpdate; - } - } - - private void saveUpdate (EditableProperties props) throws IOException { - this.helper.putPrimaryConfigurationData(getUpdatedSharedConfigurationData(),true); - if (this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/web-project/1",true) != null) { //NOI18N - this.cfg.removeConfigurationFragment("data","http://www.netbeans.org/ns/web-project/1",true); //NOI18N - } else { - this.cfg.removeConfigurationFragment("data","http://www.netbeans.org/ns/web-project/2",true); //NOI18N - } - - boolean putProps = false; - - // AB: fix for #55597: should not update the project without adding the properties - // update is only done once, so if we don't add the properties now, we don't get another chance to do so - if (props == null) { - props = getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - putProps = true; - } - - //add properties needed by 4.1 project - if(props != null) { - props.put("test.src.dir", "test"); //NOI18N - props.put("build.test.classes.dir", "${build.dir}/test/classes"); //NOI18N - props.put("build.test.results.dir", "${build.dir}/test/results"); //NOI18N - props.put("conf.dir","${source.root}/conf"); //NOI18N - props.put("jspcompilation.classpath", "${jspc.classpath}:${javac.classpath}"); - - props.setProperty(WebProjectProperties.JAVAC_TEST_CLASSPATH, new String[] { - "${javac.classpath}:", // NOI18N - "${build.classes.dir}:", // NOI18N - "${libs.junit.classpath}:", // NOI18N - "${libs.junit_4.classpath}", // NOI18N - }); - props.setProperty(WebProjectProperties.RUN_TEST_CLASSPATH, new String[] { - "${javac.test.classpath}:", // NOI18N - "${build.test.classes.dir}", // NOI18N - }); - props.setProperty(WebProjectProperties.DEBUG_TEST_CLASSPATH, new String[] { - "${run.test.classpath}", // NOI18N - }); - - props.put(WebProjectProperties.WAR_EAR_NAME, props.getProperty(WebProjectProperties.WAR_NAME)); - props.put(WebProjectProperties.DIST_WAR_EAR, "${dist.dir}/${war.ear.name}"); - - if (props.getProperty(WebProjectProperties.LIBRARIES_DIR) == null) { - props.setProperty(WebProjectProperties.LIBRARIES_DIR, "${" + WebProjectProperties.WEB_DOCBASE_DIR + "}/WEB-INF/lib"); //NOI18N - } - } - - if(props != null) { - //remove jsp20 and servlet24 libraries - ReferenceHelper refHelper = new ReferenceHelper(helper, cfg, helper.getStandardPropertyEvaluator()); - ClassPathSupport cs = new ClassPathSupport( helper.getStandardPropertyEvaluator(), refHelper, helper, - WebProjectProperties.WELL_KNOWN_PATHS, - WebProjectProperties.LIBRARY_PREFIX, - WebProjectProperties.LIBRARY_SUFFIX, - WebProjectProperties.ANT_ARTIFACT_PREFIX ); - Iterator items = cs.itemsIterator((String)props.get( WebProjectProperties.JAVAC_CLASSPATH ), ClassPathSupport.TAG_WEB_MODULE_LIBRARIES); - ArrayList cpItems = new ArrayList(); - while(items.hasNext()) { - ClassPathSupport.Item cpti = (ClassPathSupport.Item)items.next(); - String propertyName = cpti.getReference(); - if(propertyName != null) { - String libname = propertyName.substring("${libs.".length()); - if(libname.indexOf(".classpath}") != -1) libname = libname.substring(0, libname.indexOf(".classpath}")); - - if(!("servlet24".equals(libname) || "jsp20".equals(libname))) { //NOI18N - cpItems.add(cpti); - } - } - } - String[] javac_cp = cs.encodeToStrings(cpItems.iterator(), ClassPathSupport.TAG_WEB_MODULE_LIBRARIES ); - props.setProperty( WebProjectProperties.JAVAC_CLASSPATH, javac_cp ); - } - - if (putProps) { - helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); - } - - ProjectManager.getDefault().saveProject (this.project); - synchronized(this) { - this.isCurrent = Boolean.TRUE; - } - - //fire project updated - if(projectUpdateListener != null) projectUpdateListener.projectUpdated(); - - //create conf dir if doesn't exist and copy default manifest inside - try { - //I cannot use ${conf.dir} since the PE doesn't know about it - //String confDir = helper.getStandardPropertyEvaluator().evaluate("${source.root}/conf"); //NOI18N - FileObject prjFO = project.getProjectDirectory(); - // folder creation will throw IOE if already exists - // use the hard coded string due to issue #54882 - since the 4.0 supports creation of only jakarta structure projects the conf dir is always in project root - FileObject confDirFO = prjFO.createFolder("conf");//NOI18N - // copyfile will throw IOE if the file already exists - FileUtil.copyFile(Repository.getDefault().getDefaultFileSystem().findResource("org-netbeans-modules-web-project/MANIFEST.MF"), confDirFO, "MANIFEST"); //NOI18N - }catch(IOException e) { - //just ignore - } - - } - - private synchronized Element getUpdatedSharedConfigurationData () { - if (cachedElement == null) { - int version = 1; - Element oldRoot = this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/web-project/1",true); //NOI18N - if (oldRoot == null) { - version = 2; - oldRoot = this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/web-project/2",true); //NOI18N - } - final String ns = version == 1 ? "http://www.netbeans.org/ns/web-project/1" : "http://www.netbeans.org/ns/web-project/2"; //NOI18N - if (oldRoot != null) { - Document doc = oldRoot.getOwnerDocument(); - Element newRoot = doc.createElementNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N - copyDocument (doc, oldRoot, newRoot); - if (version == 1) { - //1->2 upgrade - Element sourceRoots = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N - Element root = doc.createElementNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N - root.setAttribute ("id","src.dir"); //NOI18N - sourceRoots.appendChild(root); - newRoot.appendChild (sourceRoots); - Element testRoots = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"test-roots"); //NOI18N - root = doc.createElementNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N - root.setAttribute ("id","test.src.dir"); //NOI18N - testRoots.appendChild (root); - newRoot.appendChild (testRoots); - } - if (version == 1 || version == 2) { - //2->3 upgrade - NodeList libList = newRoot.getElementsByTagNameNS(ns, TAG_LIBRARY); - for (int i = 0; i < libList.getLength(); i++) { - if (libList.item(i).getNodeType() == Node.ELEMENT_NODE) { - Element library = (Element) libList.item(i); - Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0); - //remove ${ and } from the beginning and end - String webFileText = findText(webFile); - webFileText = webFileText.substring(2, webFileText.length() - 1); -// warIncludesMap.put(webFileText, pathInWarElements.getLength() > 0 ? findText((Element) pathInWarElements.item(0)) : Item.PATH_IN_WAR_NONE); - if (webFileText.startsWith ("lib.")) { - String libName = webFileText.substring(6, webFileText.indexOf(".classpath")); //NOI18N - List/**/ roots = LibraryManager.getDefault().getLibrary(libName).getContent("classpath"); //NOI18N - ArrayList files = new ArrayList (); - ArrayList dirs = new ArrayList (); - for (Iterator it = roots.iterator(); it.hasNext();) { - URL rootUrl = (URL) it.next(); - FileObject root = URLMapper.findFileObject (rootUrl); - if ("jar".equals(rootUrl.getProtocol())) { //NOI18N - root = FileUtil.getArchiveFile (root); - } - if (root != null) { - if (root.isData()) { - files.add(root); - } else { - dirs.add(root); - } - } - } - if (files.size() > 0) { - library.setAttribute(ATTR_FILES, "" + files.size()); - } - if (dirs.size() > 0) { - library.setAttribute(ATTR_DIRS, "" + dirs.size()); - } - } - } - } - } - cachedElement = updateMinAntVersion(newRoot, doc); - } - } - return cachedElement; - } - - private synchronized EditableProperties getUpdatedProjectProperties () { - if (cachedProperties == null) { - cachedProperties = this.helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - //The javadoc.additionalparam was not in NB 4.0 - if (cachedProperties.get (WebProjectProperties.JAVADOC_ADDITIONALPARAM)==null) { - cachedProperties.put (WebProjectProperties.JAVADOC_ADDITIONALPARAM,""); //NOI18N - } - } - return this.cachedProperties; - } - - private static void copyDocument (Document doc, Element from, Element to) { - NodeList nl = from.getChildNodes(); - int length = nl.getLength(); - for (int i=0; i< length; i++) { - Node node = nl.item (i); - Node newNode = null; - switch (node.getNodeType()) { - case Node.ELEMENT_NODE: - Element oldElement = (Element) node; - newNode = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName()); - NamedNodeMap m = oldElement.getAttributes(); - Element newElement = (Element) newNode; - for (int index = 0; index < m.getLength(); index++) { - Node attr = m.item(index); - newElement.setAttribute(attr.getNodeName(), attr.getNodeValue()); - } - copyDocument(doc,oldElement,(Element)newNode); - break; - case Node.TEXT_NODE: - Text oldText = (Text) node; - newNode = doc.createTextNode(oldText.getData()); - break; - case Node.COMMENT_NODE: - Comment oldComment = (Comment) node; - newNode = doc.createComment(oldComment.getData()); - break; - } - if (newNode != null) { - to.appendChild (newNode); - } - } - } - - private static Element updateMinAntVersion (final Element root, final Document doc) { - NodeList list = root.getElementsByTagNameNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,TAG_MINIMUM_ANT_VERSION); - if (list.getLength() == 1) { - Element me = (Element) list.item(0); - list = me.getChildNodes(); - if (list.getLength() == 1) { - me.replaceChild (doc.createTextNode(WebProjectUtilities.MINIMUM_ANT_VERSION), list.item(0)); - return root; - } - } - assert false : "Invalid project file"; //NOI18N - return root; - } - - /** - * Creates an default Notifier. The default notifier displays a dialog warning user about project update. - * @return notifier - */ - public static Notifier createDefaultNotifier () { - return new Notifier() { - public boolean canUpdate() { - JButton updateOption = new JButton (NbBundle.getMessage(UpdateHelper.class, "CTL_UpdateOption")); - return DialogDisplayer.getDefault().notify( - new NotifyDescriptor (NbBundle.getMessage(UpdateHelper.class,"TXT_ProjectUpdate", BUILD_NUMBER), - NbBundle.getMessage(UpdateHelper.class,"TXT_ProjectUpdateTitle"), - NotifyDescriptor.DEFAULT_OPTION, - NotifyDescriptor.WARNING_MESSAGE, - new Object[] { - updateOption, - NotifyDescriptor.CANCEL_OPTION - }, - updateOption)) == updateOption; - } - }; - } - - /** - * Extract nested text from a node. - * Currently does not handle coalescing text nodes, CDATA sections, etc. - * @param parent a parent node - * @return the nested text, or null if none was found - */ - private static String findText(Node parent) { - NodeList l = parent.getChildNodes(); - for (int i = 0; i < l.getLength(); i++) { - if (l.item(i).getNodeType() == Node.TEXT_NODE) { - Text text = (Text)l.item(i); - return text.getNodeValue(); - } - } - return null; - } - - /** - * Interface used by the UpdateHelper to ask user about - * the project update. - */ - public static interface Notifier { - /** - * Asks user to update the project - * @return true if the project should be updated - */ - public boolean canUpdate (); - } - - private ProjectUpdateListener projectUpdateListener = null; - - public void setProjectUpdateListener(ProjectUpdateListener l) { - this.projectUpdateListener = l; - } - - /** Used to notify someone that the project needs to be updated. - * A workaround for #54077 - Import 4.0 project - remove Servlet/JSP APIs */ - public static interface ProjectUpdateListener { - public void projectUpdated(); - } - -} diff --git a/web.project/src/org/netbeans/modules/web/project/UpdateProjectImpl.java b/web.project/src/org/netbeans/modules/web/project/UpdateProjectImpl.java new file mode 100644 --- /dev/null +++ b/web.project/src/org/netbeans/modules/web/project/UpdateProjectImpl.java @@ -0,0 +1,431 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.web.project; + +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import javax.swing.JButton; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.api.project.libraries.LibraryManager; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; +import org.netbeans.modules.java.api.common.ant.UpdateImplementation; +import org.netbeans.modules.web.project.api.WebProjectUtilities; +import org.netbeans.modules.web.project.classpath.ClassPathSupport; +import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties; +import org.netbeans.spi.project.AuxiliaryConfiguration; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.EditableProperties; +import org.netbeans.spi.project.support.ant.ReferenceHelper; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.filesystems.Repository; +import org.openide.filesystems.URLMapper; +import org.openide.util.Mutex; +import org.openide.util.NbBundle; +import org.w3c.dom.Comment; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +/** + * + * @author Tomas Mysik + */ +public class UpdateProjectImpl implements UpdateImplementation { + + private static final boolean TRANSPARENT_UPDATE = Boolean.getBoolean("webproject.transparentUpdate"); + private static final String BUILD_NUMBER = System.getProperty("netbeans.buildnumber"); // NOI18N + private static final String TAG_MINIMUM_ANT_VERSION = "minimum-ant-version"; // NOI18N + private static final String TAG_FILE = "file"; //NOI18N + private static final String TAG_LIBRARY = "library"; //NOI18N + private static final String ATTR_FILES = "files"; //NOI18N + private static final String ATTR_DIRS = "dirs"; //NOI18N + + private final Project project; + private final AntProjectHelper helper; + private final AuxiliaryConfiguration cfg; + private boolean alreadyAskedInWriteAccess; + private Boolean isCurrent; + private Element cachedElement; + private ProjectUpdateListener projectUpdateListener = null; + private UpdateHelper updateHelper; + private EditableProperties cachedProperties; + + /** + * Creates new UpdateHelper + * @param project + * @param helper AntProjectHelper + * @param cfg AuxiliaryConfiguration + * @param genFileHelper GeneratedFilesHelper + * @param notifier used to ask user about project update + */ + UpdateProjectImpl(Project project, AntProjectHelper helper, AuxiliaryConfiguration cfg) { + assert project != null && helper != null && cfg != null; + this.project = project; + this.helper = helper; + this.cfg = cfg; + } + + public void setUpdateHelper(UpdateHelper updateHelper) { + this.updateHelper = updateHelper; + } + + public boolean isCurrent() { + return ProjectManager.mutex().readAccess(new Mutex.Action() { + public Boolean run() { + synchronized (this) { + if (isCurrent == null) { + if ((cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/web-project/1",true) != null) || // NOI18N + (cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/web-project/2",true) != null)) { // NOI18N + isCurrent = Boolean.FALSE; + } else { + isCurrent = Boolean.TRUE; + } + } + return isCurrent; + } + } + }).booleanValue(); + } + + public boolean canUpdate () { + if (TRANSPARENT_UPDATE) { + return true; + } + //Ask just once under a single write access + if (alreadyAskedInWriteAccess) { + return false; + } + else { + boolean canUpdate = showUpdateDialog(); + if (!canUpdate) { + alreadyAskedInWriteAccess = true; + ProjectManager.mutex().postReadRequest(new Runnable() { + public void run() { + alreadyAskedInWriteAccess = false; + } + }); + } + return canUpdate; + } + } + + public void saveUpdate(EditableProperties props) throws IOException { + this.helper.putPrimaryConfigurationData(getUpdatedSharedConfigurationData(),true); + if (this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/web-project/1",true) != null) { //NOI18N + this.cfg.removeConfigurationFragment("data","http://www.netbeans.org/ns/web-project/1",true); //NOI18N + } else { + this.cfg.removeConfigurationFragment("data","http://www.netbeans.org/ns/web-project/2",true); //NOI18N + } + + boolean putProps = false; + + // AB: fix for #55597: should not update the project without adding the properties + // update is only done once, so if we don't add the properties now, we don't get another chance to do so + if (props == null) { + assert updateHelper != null; + props = updateHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + putProps = true; + } + + //add properties needed by 4.1 project + if(props != null) { + props.put("test.src.dir", "test"); //NOI18N + props.put("build.test.classes.dir", "${build.dir}/test/classes"); //NOI18N + props.put("build.test.results.dir", "${build.dir}/test/results"); //NOI18N + props.put("conf.dir","${source.root}/conf"); //NOI18N + props.put("jspcompilation.classpath", "${jspc.classpath}:${javac.classpath}"); + + props.setProperty(WebProjectProperties.JAVAC_TEST_CLASSPATH, new String[] { + "${javac.classpath}:", // NOI18N + "${build.classes.dir}:", // NOI18N + "${libs.junit.classpath}:", // NOI18N + "${libs.junit_4.classpath}", // NOI18N + }); + props.setProperty(WebProjectProperties.RUN_TEST_CLASSPATH, new String[] { + "${javac.test.classpath}:", // NOI18N + "${build.test.classes.dir}", // NOI18N + }); + props.setProperty(WebProjectProperties.DEBUG_TEST_CLASSPATH, new String[] { + "${run.test.classpath}", // NOI18N + }); + + props.put(WebProjectProperties.WAR_EAR_NAME, props.getProperty(WebProjectProperties.WAR_NAME)); + props.put(WebProjectProperties.DIST_WAR_EAR, "${dist.dir}/${war.ear.name}"); + + if (props.getProperty(WebProjectProperties.LIBRARIES_DIR) == null) { + props.setProperty(WebProjectProperties.LIBRARIES_DIR, "${" + WebProjectProperties.WEB_DOCBASE_DIR + "}/WEB-INF/lib"); //NOI18N + } + } + + if(props != null) { + //remove jsp20 and servlet24 libraries + ReferenceHelper refHelper = new ReferenceHelper(helper, cfg, helper.getStandardPropertyEvaluator()); + ClassPathSupport cs = new ClassPathSupport( helper.getStandardPropertyEvaluator(), refHelper, helper, + WebProjectProperties.WELL_KNOWN_PATHS, + WebProjectProperties.LIBRARY_PREFIX, + WebProjectProperties.LIBRARY_SUFFIX, + WebProjectProperties.ANT_ARTIFACT_PREFIX ); + Iterator items = cs.itemsIterator((String)props.get( WebProjectProperties.JAVAC_CLASSPATH ), ClassPathSupport.TAG_WEB_MODULE_LIBRARIES); + ArrayList cpItems = new ArrayList(); + while(items.hasNext()) { + ClassPathSupport.Item cpti = (ClassPathSupport.Item)items.next(); + String propertyName = cpti.getReference(); + if(propertyName != null) { + String libname = propertyName.substring("${libs.".length()); + if(libname.indexOf(".classpath}") != -1) libname = libname.substring(0, libname.indexOf(".classpath}")); + + if(!("servlet24".equals(libname) || "jsp20".equals(libname))) { //NOI18N + cpItems.add(cpti); + } + } + } + String[] javac_cp = cs.encodeToStrings(cpItems.iterator(), ClassPathSupport.TAG_WEB_MODULE_LIBRARIES ); + props.setProperty( WebProjectProperties.JAVAC_CLASSPATH, javac_cp ); + } + + if (putProps) { + helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); + } + + ProjectManager.getDefault().saveProject (this.project); + synchronized(this) { + this.isCurrent = Boolean.TRUE; + } + + //fire project updated + if(projectUpdateListener != null) projectUpdateListener.projectUpdated(); + + //create conf dir if doesn't exist and copy default manifest inside + try { + //I cannot use ${conf.dir} since the PE doesn't know about it + //String confDir = helper.getStandardPropertyEvaluator().evaluate("${source.root}/conf"); //NOI18N + FileObject prjFO = project.getProjectDirectory(); + // folder creation will throw IOE if already exists + // use the hard coded string due to issue #54882 - since the 4.0 supports creation of only jakarta structure projects the conf dir is always in project root + FileObject confDirFO = prjFO.createFolder("conf");//NOI18N + // copyfile will throw IOE if the file already exists + FileUtil.copyFile(Repository.getDefault().getDefaultFileSystem().findResource("org-netbeans-modules-web-project/MANIFEST.MF"), confDirFO, "MANIFEST"); //NOI18N + }catch(IOException e) { + //just ignore + } + } + + public synchronized Element getUpdatedSharedConfigurationData () { + if (cachedElement == null) { + int version = 1; + Element oldRoot = this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/web-project/1",true); //NOI18N + if (oldRoot == null) { + version = 2; + oldRoot = this.cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/web-project/2",true); //NOI18N + } + final String ns = version == 1 ? "http://www.netbeans.org/ns/web-project/1" : "http://www.netbeans.org/ns/web-project/2"; //NOI18N + if (oldRoot != null) { + Document doc = oldRoot.getOwnerDocument(); + Element newRoot = doc.createElementNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N + copyDocument (doc, oldRoot, newRoot); + if (version == 1) { + //1->2 upgrade + Element sourceRoots = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N + Element root = doc.createElementNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N + root.setAttribute ("id","src.dir"); //NOI18N + sourceRoots.appendChild(root); + newRoot.appendChild (sourceRoots); + Element testRoots = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"test-roots"); //NOI18N + root = doc.createElementNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N + root.setAttribute ("id","test.src.dir"); //NOI18N + testRoots.appendChild (root); + newRoot.appendChild (testRoots); + } + if (version == 1 || version == 2) { + //2->3 upgrade + NodeList libList = newRoot.getElementsByTagNameNS(ns, TAG_LIBRARY); + for (int i = 0; i < libList.getLength(); i++) { + if (libList.item(i).getNodeType() == Node.ELEMENT_NODE) { + Element library = (Element) libList.item(i); + Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0); + //remove ${ and } from the beginning and end + String webFileText = findText(webFile); + webFileText = webFileText.substring(2, webFileText.length() - 1); +// warIncludesMap.put(webFileText, pathInWarElements.getLength() > 0 ? findText((Element) pathInWarElements.item(0)) : Item.PATH_IN_WAR_NONE); + if (webFileText.startsWith ("lib.")) { + String libName = webFileText.substring(6, webFileText.indexOf(".classpath")); //NOI18N + List/**/ roots = LibraryManager.getDefault().getLibrary(libName).getContent("classpath"); //NOI18N + ArrayList files = new ArrayList (); + ArrayList dirs = new ArrayList (); + for (Iterator it = roots.iterator(); it.hasNext();) { + URL rootUrl = (URL) it.next(); + FileObject root = URLMapper.findFileObject (rootUrl); + if ("jar".equals(rootUrl.getProtocol())) { //NOI18N + root = FileUtil.getArchiveFile (root); + } + if (root != null) { + if (root.isData()) { + files.add(root); + } else { + dirs.add(root); + } + } + } + if (files.size() > 0) { + library.setAttribute(ATTR_FILES, "" + files.size()); + } + if (dirs.size() > 0) { + library.setAttribute(ATTR_DIRS, "" + dirs.size()); + } + } + } + } + } + cachedElement = updateMinAntVersion(newRoot, doc); + } + } + return cachedElement; + } + + public synchronized EditableProperties getUpdatedProjectProperties () { + if (cachedProperties == null) { + cachedProperties = this.helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + //The javadoc.additionalparam was not in NB 4.0 + if (cachedProperties.get (WebProjectProperties.JAVADOC_ADDITIONALPARAM)==null) { + cachedProperties.put (WebProjectProperties.JAVADOC_ADDITIONALPARAM,""); //NOI18N + } + } + return this.cachedProperties; + } + + /** + * Extract nested text from a node. + * Currently does not handle coalescing text nodes, CDATA sections, etc. + * @param parent a parent node + * @return the nested text, or null if none was found + */ + private static String findText(Node parent) { + NodeList l = parent.getChildNodes(); + for (int i = 0; i < l.getLength(); i++) { + if (l.item(i).getNodeType() == Node.TEXT_NODE) { + Text text = (Text)l.item(i); + return text.getNodeValue(); + } + } + return null; + } + + private static void copyDocument (Document doc, Element from, Element to) { + NodeList nl = from.getChildNodes(); + int length = nl.getLength(); + for (int i=0; i< length; i++) { + Node node = nl.item (i); + Node newNode = null; + switch (node.getNodeType()) { + case Node.ELEMENT_NODE: + Element oldElement = (Element) node; + newNode = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName()); + NamedNodeMap m = oldElement.getAttributes(); + Element newElement = (Element) newNode; + for (int index = 0; index < m.getLength(); index++) { + Node attr = m.item(index); + newElement.setAttribute(attr.getNodeName(), attr.getNodeValue()); + } + copyDocument(doc,oldElement,(Element)newNode); + break; + case Node.TEXT_NODE: + Text oldText = (Text) node; + newNode = doc.createTextNode(oldText.getData()); + break; + case Node.COMMENT_NODE: + Comment oldComment = (Comment) node; + newNode = doc.createComment(oldComment.getData()); + break; + } + if (newNode != null) { + to.appendChild (newNode); + } + } + } + + private static Element updateMinAntVersion (final Element root, final Document doc) { + NodeList list = root.getElementsByTagNameNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,TAG_MINIMUM_ANT_VERSION); + if (list.getLength() == 1) { + Element me = (Element) list.item(0); + list = me.getChildNodes(); + if (list.getLength() == 1) { + me.replaceChild (doc.createTextNode(WebProjectUtilities.MINIMUM_ANT_VERSION), list.item(0)); + return root; + } + } + assert false : "Invalid project file"; //NOI18N + return root; + } + + private boolean showUpdateDialog() { + JButton updateOption = new JButton (NbBundle.getMessage(UpdateProjectImpl.class, "CTL_UpdateOption")); + updateOption.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(UpdateProjectImpl.class, "AD_UpdateOption")); + return DialogDisplayer.getDefault().notify( + new NotifyDescriptor (NbBundle.getMessage(UpdateProjectImpl.class,"TXT_ProjectUpdate", BUILD_NUMBER), + NbBundle.getMessage(UpdateProjectImpl.class,"TXT_ProjectUpdateTitle"), + NotifyDescriptor.DEFAULT_OPTION, + NotifyDescriptor.WARNING_MESSAGE, + new Object[] { + updateOption, + NotifyDescriptor.CANCEL_OPTION + }, + updateOption)) == updateOption; + } + + public void setProjectUpdateListener(ProjectUpdateListener l) { + this.projectUpdateListener = l; + } + + /** Used to notify someone that the project needs to be updated. + * A workaround for #54077 - Import 4.0 project - remove Servlet/JSP APIs */ + public static interface ProjectUpdateListener { + public void projectUpdated(); + } +} diff --git a/web.project/src/org/netbeans/modules/web/project/WebActionProvider.java b/web.project/src/org/netbeans/modules/web/project/WebActionProvider.java --- a/web.project/src/org/netbeans/modules/web/project/WebActionProvider.java +++ b/web.project/src/org/netbeans/modules/web/project/WebActionProvider.java @@ -86,9 +86,8 @@ import org.netbeans.modules.web.api.webm import org.netbeans.modules.web.api.webmodule.WebModule; import org.netbeans.modules.web.api.webmodule.WebProjectConstants; import java.util.HashSet; -import java.util.logging.Level; -import java.util.logging.Logger; import org.netbeans.api.fileinfo.NonRecursiveFolder; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.modules.web.api.webmodule.RequestParametersQuery; import org.netbeans.modules.web.jsps.parserapi.JspParserAPI; import org.netbeans.modules.web.jsps.parserapi.JspParserFactory; @@ -98,7 +97,6 @@ import org.netbeans.modules.websvc.api.w import org.netbeans.modules.websvc.api.webservices.WebServicesSupport; import org.netbeans.modules.websvc.api.webservices.WsCompileEditorSupport; import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.EditableProperties; import org.netbeans.spi.project.support.ant.PropertyUtils; import org.openide.DialogDescriptor; import org.openide.util.Exceptions; diff --git a/web.project/src/org/netbeans/modules/web/project/WebFileBuiltQuery.java b/web.project/src/org/netbeans/modules/web/project/WebFileBuiltQuery.java deleted file mode 100644 --- a/web.project/src/org/netbeans/modules/web/project/WebFileBuiltQuery.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.web.project; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import org.openide.filesystems.FileObject; -import org.netbeans.api.queries.FileBuiltQuery; -import org.netbeans.spi.queries.FileBuiltQueryImplementation; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties; - -public class WebFileBuiltQuery implements FileBuiltQueryImplementation, PropertyChangeListener { - - private FileBuiltQueryImplementation delegate; - private final AntProjectHelper helper; - private final PropertyEvaluator evaluator; - private final SourceRoots sourceRoots; - private final SourceRoots testRoots; - - WebFileBuiltQuery (AntProjectHelper helper, PropertyEvaluator evaluator, - SourceRoots sourceRoots, SourceRoots testRoots) { - this.helper = helper; - this.evaluator = evaluator; - this.sourceRoots = sourceRoots; - this.testRoots = testRoots; - } - - public synchronized FileBuiltQuery.Status getStatus(FileObject file) { - if (this.delegate == null) { - this.delegate = createDelegate (); - } - return this.delegate.getStatus (file); - } - - private FileBuiltQueryImplementation createDelegate () { - String[] srcRoots = this.sourceRoots.getRootProperties(); - String[] tstRoots = this.testRoots.getRootProperties(); - String[] from = new String [srcRoots.length + tstRoots.length]; - String[] to = new String [srcRoots.length + tstRoots.length]; - for (int i=0; i< srcRoots.length; i++) { - from[i] = "${" + srcRoots[i] + "}/*.java"; // NOI18N - to[i] = "${" + WebProjectProperties.BUILD_CLASSES_DIR + "}/*.class"; // NOI18N - } - for (int i=0; i*/ cache = new HashMap (); - - public CompiledSourceForBinaryQuery (AntProjectHelper helper, PropertyEvaluator evaluator, SourceRoots srcRoots, SourceRoots testRoots) { - this.helper = helper; - this.evaluator = evaluator; - this.sourceRoots = srcRoots; - this.testRoots = testRoots; - } - - public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) { - if (FileUtil.getArchiveFile(binaryRoot) != null) { - binaryRoot = FileUtil.getArchiveFile(binaryRoot); - // XXX check whether this is really the root - } - SourceForBinaryQuery.Result res = (SourceForBinaryQuery.Result) cache.get (binaryRoot); - if (res != null) { - return res; - } - SourceRoots src = null; - if (hasSources(binaryRoot, WebProjectProperties.BUILD_CLASSES_DIR)) { //NOI18N - src = this.sourceRoots; - } - else if (hasSources (binaryRoot, WebProjectProperties.DIST_WAR)) { //NOI18N - src = this.sourceRoots; - } - else if (hasSources (binaryRoot, WebProjectProperties.BUILD_TEST_CLASSES_DIR)) { //NOI18N - src = this.testRoots; - } - if (src == null) { - return null; - } - else { - res = new Result (src); - cache.put (binaryRoot, res); - return res; - } - } - - - private boolean hasSources (URL binaryRoot, String binaryProperty) { - try { - String outDir = evaluator.getProperty(binaryProperty); - if (outDir != null) { - File f = helper.resolveFile (outDir); - URL url = f.toURI().toURL(); - if (!f.exists() && !f.getPath().toLowerCase().endsWith(".jar")) { // NOI18N - // non-existing - assert !url.toExternalForm().endsWith("/") : f; // NOI18N - url = new URL(url.toExternalForm() + "/"); // NOI18N - } - if (url.equals (binaryRoot)) { - return true; - } - } - } catch (MalformedURLException malformedURL) { - Exceptions.printStackTrace(malformedURL); - } - return false; - } - - private static class Result implements SourceForBinaryQuery.Result, PropertyChangeListener { - - private final ChangeSupport changeSupport = new ChangeSupport(this); - private SourceRoots sourceRoots; - - public Result (SourceRoots sourceRoots) { - this.sourceRoots = sourceRoots; - this.sourceRoots.addPropertyChangeListener(this); - } - - public FileObject[] getRoots () { - return this.sourceRoots.getRoots(); //No need to cache it, SourceRoots does - } - - public void addChangeListener (ChangeListener l) { - changeSupport.addChangeListener(l); - } - - public void removeChangeListener (ChangeListener l) { - changeSupport.removeChangeListener(l); - } - - public void propertyChange(PropertyChangeEvent evt) { - if (SourceRoots.PROP_ROOTS.equals(evt.getPropertyName())) { - this.changeSupport.fireChange (); - } - } - - } - -} diff --git a/web.project/src/org/netbeans/modules/web/project/queries/JavadocForBinaryQueryImpl.java b/web.project/src/org/netbeans/modules/web/project/queries/JavadocForBinaryQueryImpl.java deleted file mode 100644 --- a/web.project/src/org/netbeans/modules/web/project/queries/JavadocForBinaryQueryImpl.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.web.project.queries; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.File; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.openide.filesystems.FileUtil; -import java.net.URL; -import java.net.MalformedURLException; -import javax.swing.event.ChangeListener; -import org.netbeans.api.java.queries.JavadocForBinaryQuery; -import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties; -import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.openide.util.ChangeSupport; -import org.openide.util.Exceptions; -import org.openide.util.WeakListeners; - -/** - * Finds Javadoc (if it is built) corresponding to binaries in web project. - * @author David Konecny, Jesse Glick - */ -public class JavadocForBinaryQueryImpl implements JavadocForBinaryQueryImplementation { - - private final AntProjectHelper helper; - private final PropertyEvaluator evaluator; - - public JavadocForBinaryQueryImpl(AntProjectHelper helper, PropertyEvaluator evaluator) { - this.helper = helper; - this.evaluator = evaluator; - } - - public JavadocForBinaryQuery.Result findJavadoc(final URL binaryRoot) { - - class R implements JavadocForBinaryQuery.Result, PropertyChangeListener { - - private final ChangeSupport changeSupport = new ChangeSupport(this); - private URL[] result; - - public R () { - JavadocForBinaryQueryImpl.this.evaluator.addPropertyChangeListener (WeakListeners.propertyChange(this,JavadocForBinaryQueryImpl.this.evaluator)); - } - - public synchronized URL[] getRoots() { - if (this.result == null) { - String javadocDir = evaluator.getProperty(WebProjectProperties.DIST_JAVADOC_DIR); - if (javadocDir != null) { - File f = helper.resolveFile(javadocDir); - try { - URL url = f.toURI().toURL(); - if (!f.exists()) { - assert !url.toExternalForm().endsWith("/") : f; // NOI18N - url = new URL(url.toExternalForm() + "/"); // NOI18N - } - this.result = new URL[] {url}; - } catch (MalformedURLException e) { - this.result = new URL[0]; - Exceptions.printStackTrace(e); - } - } - else { - this.result = new URL[0]; - } - } - return this.result; - } - public void addChangeListener(final ChangeListener l) { - assert l != null; - changeSupport.addChangeListener(l); - } - public void removeChangeListener(final ChangeListener l) { - assert l != null; - changeSupport.removeChangeListener(l); - } - - public void propertyChange (final PropertyChangeEvent event) { - if (WebProjectProperties.DIST_JAVADOC_DIR.equals(event.getPropertyName())) { - synchronized (this) { - result = null; - } - this.changeSupport.fireChange (); - } - } - } - if (isRootOwner(binaryRoot, WebProjectProperties.BUILD_CLASSES_DIR) || isRootOwner (binaryRoot, WebProjectProperties.DIST_WAR)) { - return new R(); - } - return null; - } - - private boolean isRootOwner (URL binaryRoot, String binaryProperty) { - try { - if (FileUtil.getArchiveFile(binaryRoot) != null) { - binaryRoot = FileUtil.getArchiveFile(binaryRoot); - // XXX check whether this is really the root - } - String outDir = evaluator.getProperty(binaryProperty); - if (outDir != null) { - File f = helper.resolveFile (outDir); - URL url = f.toURI().toURL(); - if (!f.exists() && !f.getPath().toLowerCase().endsWith(".jar")) { // NOI18N - assert !url.toExternalForm().endsWith("/") : f; // NOI18N - url = new URL(url.toExternalForm() + "/"); // NOI18N - } - return url.equals(binaryRoot) || - binaryRoot.toExternalForm().startsWith(url.toExternalForm()); - } - } catch (MalformedURLException malformedURL) { - Exceptions.printStackTrace(malformedURL); - } - return false; - } - -// private URL getJavadoc(URL binaryRoot, String binaryProperty, String javadocProperty) { -// try { -// if (FileUtil.getArchiveFile(binaryRoot) != null) { -// binaryRoot = FileUtil.getArchiveFile(binaryRoot); -// } -// String outDir = evaluator.getProperty(binaryProperty); -// if (outDir != null) { -// File f = helper.resolveFile (outDir); -// URL url = f.toURI().toURL(); -// if (!f.exists() && !f.getPath().toLowerCase().endsWith(".jar")) { -// assert !url.toExternalForm().endsWith("/") : f; -// url = new URL(url.toExternalForm() + "/"); -// } -// if (url.equals(binaryRoot) || -// binaryRoot.toExternalForm().startsWith(url.toExternalForm())) { -// String javadocDir = evaluator.getProperty(javadocProperty); -// if (javadocDir != null) { -// f = helper.resolveFile(javadocDir); -// return f.toURI().toURL(); -// } -// } -// } -// } catch (MalformedURLException malformedURL) { -// ErrorManager.getDefault().notify(malformedURL); -// } -// return null; -// } - -} diff --git a/web.project/src/org/netbeans/modules/web/project/queries/SourceLevelQueryImpl.java b/web.project/src/org/netbeans/modules/web/project/queries/SourceLevelQueryImpl.java deleted file mode 100644 --- a/web.project/src/org/netbeans/modules/web/project/queries/SourceLevelQueryImpl.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.web.project.queries; - -import org.openide.filesystems.FileObject; - -import org.netbeans.api.java.platform.JavaPlatform; -import org.netbeans.api.java.platform.JavaPlatformManager; -import org.netbeans.api.java.platform.Specification; -import org.netbeans.spi.java.queries.SourceLevelQueryImplementation; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.spi.project.support.ant.PropertyUtils; -import org.netbeans.spi.project.support.ant.EditableProperties; - -/** - * Returns source level of project sources. - * @author David Konecny - */ -public class SourceLevelQueryImpl implements SourceLevelQueryImplementation { - - private final PropertyEvaluator evaluator; - - public SourceLevelQueryImpl(PropertyEvaluator evaluator) { - this.evaluator = evaluator; - } - - public String getSourceLevel(FileObject javaFile) { - boolean platformExists = false; - String activePlatform = evaluator.getProperty ("platform.active"); //NOI18N - if (activePlatform != null && activePlatform.length()>0) { - JavaPlatform[] j2sePlatforms = JavaPlatformManager.getDefault().getPlatforms(null, new Specification("j2se",null)); //NOI18N - for (int i=0; i< j2sePlatforms.length; i++) { - String antName = (String) j2sePlatforms[i].getProperties().get("platform.ant.name"); //NOI18N - if (antName != null && antName.equals(activePlatform)) { - platformExists = true; - break; - } - } - } - if (platformExists) { - String sl = evaluator.getProperty("javac.source"); //NOI18N - if (sl != null && sl.length() > 0) { - return sl; - } else { - return null; - } - } - else { - EditableProperties props = PropertyUtils.getGlobalProperties(); - String sl = (String) props.get("default.javac.source"); //NOI18N - if (sl != null && sl.length() > 0) { - return sl; - } else { - return null; - } - } - } - -} diff --git a/web.project/src/org/netbeans/modules/web/project/queries/UnitTestForSourceQueryImpl.java b/web.project/src/org/netbeans/modules/web/project/queries/UnitTestForSourceQueryImpl.java deleted file mode 100644 --- a/web.project/src/org/netbeans/modules/web/project/queries/UnitTestForSourceQueryImpl.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.web.project.queries; - -import java.net.URL; -import org.netbeans.api.project.FileOwnerQuery; -import org.netbeans.api.project.Project; -import org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation; -import org.netbeans.modules.web.project.SourceRoots; -import org.openide.filesystems.FileObject; - -public class UnitTestForSourceQueryImpl implements MultipleRootsUnitTestForSourceQueryImplementation { - - private final SourceRoots sourceRoots; - private final SourceRoots testRoots; - - public UnitTestForSourceQueryImpl(SourceRoots sourceRoots, SourceRoots testRoots) { - this.sourceRoots = sourceRoots; - this.testRoots = testRoots; - } - - public URL[] findUnitTests(FileObject source) { - return find(source, sourceRoots, testRoots); // NOI18N - } - - public URL[] findSources(FileObject unitTest) { - return find(unitTest, testRoots, sourceRoots); // NOI18N - } - - private URL[] find(FileObject file, SourceRoots from, SourceRoots to) { - Project p = FileOwnerQuery.getOwner(file); - if (p == null) { - return null; - } - FileObject[] fromRoots = from.getRoots(); - for (int i = 0; i < fromRoots.length; i++) { - if (fromRoots[i].equals(file)) { - return to.getRootURLs(); - } - } - return null; - } - -} diff --git a/web.project/src/org/netbeans/modules/web/project/queries/WebProjectEncodingQueryImpl.java b/web.project/src/org/netbeans/modules/web/project/queries/WebProjectEncodingQueryImpl.java deleted file mode 100644 --- a/web.project/src/org/netbeans/modules/web/project/queries/WebProjectEncodingQueryImpl.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.web.project.queries; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.nio.charset.Charset; -import java.nio.charset.IllegalCharsetNameException; -import org.netbeans.api.queries.FileEncodingQuery; -import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties; -import org.netbeans.spi.queries.FileEncodingQueryImplementation; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.openide.filesystems.FileObject; - -/** - * - * @author Tomas Zezula - */ -public class WebProjectEncodingQueryImpl extends FileEncodingQueryImplementation implements PropertyChangeListener { - - - private final PropertyEvaluator eval; - private Charset cache; - - /** Creates a new instance of J2SEProjectEncodingQueryImpl */ - public WebProjectEncodingQueryImpl(final PropertyEvaluator eval) { - assert eval != null; - this.eval = eval; - this.eval.addPropertyChangeListener(this); - } - - public Charset getEncoding(FileObject file) { - assert file != null; - synchronized (this) { - if (cache != null) { - return cache; - } - } - String enc = eval.getProperty(WebProjectProperties.SOURCE_ENCODING); - synchronized (this) { - if (cache == null) { - try { - cache = enc == null ? Charset.defaultCharset() : Charset.forName(enc); - } catch (IllegalCharsetNameException exception) { - return null; - } - } - return cache; - } - } - - public void propertyChange(PropertyChangeEvent event) { - String propName = event.getPropertyName(); - if (propName == null || propName.equals(WebProjectProperties.SOURCE_ENCODING)) { - synchronized (this) { - cache = null; - } - } - } - -} diff --git a/web.project/src/org/netbeans/modules/web/project/ui/ActionFilterNode.java b/web.project/src/org/netbeans/modules/web/project/ui/ActionFilterNode.java --- a/web.project/src/org/netbeans/modules/web/project/ui/ActionFilterNode.java +++ b/web.project/src/org/netbeans/modules/web/project/ui/ActionFilterNode.java @@ -65,12 +65,12 @@ import org.netbeans.api.project.FileOwne import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; import org.netbeans.api.java.queries.JavadocForBinaryQuery; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.EditableProperties; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.ReferenceHelper; -import org.netbeans.modules.web.project.UpdateHelper; import org.netbeans.modules.web.project.classpath.ClassPathSupport; import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties; import org.openide.nodes.FilterNode.Children; diff --git a/web.project/src/org/netbeans/modules/web/project/ui/DocBaseNodeFactory.java b/web.project/src/org/netbeans/modules/web/project/ui/DocBaseNodeFactory.java --- a/web.project/src/org/netbeans/modules/web/project/ui/DocBaseNodeFactory.java +++ b/web.project/src/org/netbeans/modules/web/project/ui/DocBaseNodeFactory.java @@ -58,7 +58,7 @@ import org.netbeans.api.project.Project; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectManager; import org.netbeans.api.queries.VisibilityQuery; -import org.netbeans.modules.web.project.UpdateHelper; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.modules.web.project.WebProject; import org.netbeans.modules.web.project.ui.SourceNodeFactory.PreselectPropertiesAction; import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties; diff --git a/web.project/src/org/netbeans/modules/web/project/ui/LibrariesNode.java b/web.project/src/org/netbeans/modules/web/project/ui/LibrariesNode.java --- a/web.project/src/org/netbeans/modules/web/project/ui/LibrariesNode.java +++ b/web.project/src/org/netbeans/modules/web/project/ui/LibrariesNode.java @@ -92,6 +92,7 @@ import org.netbeans.api.java.classpath.C import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.project.JavaProjectConstants; import org.netbeans.api.java.project.classpath.ProjectClassPathModifier; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.EditableProperties; import org.netbeans.spi.project.support.ant.PropertyEvaluator; @@ -99,14 +100,12 @@ import org.netbeans.spi.project.support. import org.netbeans.spi.project.support.ant.ReferenceHelper; import org.netbeans.spi.java.project.support.ui.PackageView; import org.netbeans.spi.java.classpath.support.ClassPathSupport; -import org.netbeans.modules.web.project.UpdateHelper; import org.netbeans.modules.web.api.webmodule.WebModule; import org.netbeans.modules.web.project.WebProject; import org.netbeans.modules.web.project.ui.customizer.AntArtifactChooser; import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties; import org.netbeans.modules.web.project.ui.customizer.LibrariesChooser; import org.netbeans.spi.project.libraries.support.LibrariesSupport; -import org.openide.ErrorManager; import org.openide.util.Exceptions; import org.openide.util.lookup.Lookups; diff --git a/web.project/src/org/netbeans/modules/web/project/ui/LibrariesNodeFactory.java b/web.project/src/org/netbeans/modules/web/project/ui/LibrariesNodeFactory.java --- a/web.project/src/org/netbeans/modules/web/project/ui/LibrariesNodeFactory.java +++ b/web.project/src/org/netbeans/modules/web/project/ui/LibrariesNodeFactory.java @@ -52,8 +52,8 @@ import javax.swing.SwingUtilities; import javax.swing.SwingUtilities; import javax.swing.event.ChangeListener; import org.netbeans.api.project.Project; -import org.netbeans.modules.web.project.SourceRoots; -import org.netbeans.modules.web.project.UpdateHelper; +import org.netbeans.modules.java.api.common.SourceRoots; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.modules.web.project.WebProject; import org.netbeans.modules.web.project.ui.customizer.CustomizerLibraries; import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties; diff --git a/web.project/src/org/netbeans/modules/web/project/ui/ProjectNode.java b/web.project/src/org/netbeans/modules/web/project/ui/ProjectNode.java --- a/web.project/src/org/netbeans/modules/web/project/ui/ProjectNode.java +++ b/web.project/src/org/netbeans/modules/web/project/ui/ProjectNode.java @@ -72,12 +72,12 @@ import org.netbeans.api.project.ant.AntA import org.netbeans.api.project.ant.AntArtifact; import org.netbeans.api.project.ui.OpenProjects; import org.netbeans.api.java.queries.JavadocForBinaryQuery; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.spi.project.support.ant.EditableProperties; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.ReferenceHelper; import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties; -import org.netbeans.modules.web.project.UpdateHelper; import org.openide.filesystems.FileObject; import org.openide.util.Exceptions; import org.openide.util.Lookup; diff --git a/web.project/src/org/netbeans/modules/web/project/ui/WebLogicalViewProvider.java b/web.project/src/org/netbeans/modules/web/project/ui/WebLogicalViewProvider.java --- a/web.project/src/org/netbeans/modules/web/project/ui/WebLogicalViewProvider.java +++ b/web.project/src/org/netbeans/modules/web/project/ui/WebLogicalViewProvider.java @@ -108,9 +108,9 @@ import org.netbeans.modules.j2ee.deploym import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; +import org.netbeans.modules.java.api.common.SourceRoots; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.modules.web.api.webmodule.WebProjectConstants; -import org.netbeans.modules.web.project.SourceRoots; -import org.netbeans.modules.web.project.UpdateHelper; import org.netbeans.modules.web.project.WebProject; import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties; import org.netbeans.spi.project.AuxiliaryConfiguration; @@ -581,7 +581,7 @@ public class WebLogicalViewProvider impl public void actionPerformed(ActionEvent e) { try { - helper.requestSave(); + helper.requestUpdate(); BrokenReferencesSupport.showCustomizer(helper.getAntProjectHelper(), resolver, getBreakableProperties(), new String[]{WebProjectProperties.JAVA_PLATFORM}); run(); } catch (IOException ioe) { diff --git a/web.project/src/org/netbeans/modules/web/project/ui/customizer/CustomizerLibraries.java b/web.project/src/org/netbeans/modules/web/project/ui/customizer/CustomizerLibraries.java --- a/web.project/src/org/netbeans/modules/web/project/ui/customizer/CustomizerLibraries.java +++ b/web.project/src/org/netbeans/modules/web/project/ui/customizer/CustomizerLibraries.java @@ -53,6 +53,7 @@ import javax.swing.table.TableColumn; import javax.swing.table.TableColumn; import org.netbeans.api.java.platform.JavaPlatform; import org.netbeans.api.java.platform.PlatformsCustomizer; +import org.netbeans.modules.java.api.common.ui.PlatformUiSupport; import org.netbeans.modules.web.project.classpath.ClassPathSupport; import org.netbeans.modules.web.project.ui.WebLogicalViewProvider; import org.openide.util.HelpCtx; diff --git a/web.project/src/org/netbeans/modules/web/project/ui/customizer/CustomizerProviderImpl.java b/web.project/src/org/netbeans/modules/web/project/ui/customizer/CustomizerProviderImpl.java --- a/web.project/src/org/netbeans/modules/web/project/ui/customizer/CustomizerProviderImpl.java +++ b/web.project/src/org/netbeans/modules/web/project/ui/customizer/CustomizerProviderImpl.java @@ -51,8 +51,8 @@ import java.util.Map; import java.util.Map; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectUtils; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.modules.web.project.WebProject; -import org.netbeans.modules.web.project.UpdateHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.ReferenceHelper; import org.netbeans.spi.project.ui.CustomizerProvider; diff --git a/web.project/src/org/netbeans/modules/web/project/ui/customizer/PlatformUiSupport.java b/web.project/src/org/netbeans/modules/web/project/ui/customizer/PlatformUiSupport.java deleted file mode 100644 --- a/web.project/src/org/netbeans/modules/web/project/ui/customizer/PlatformUiSupport.java +++ /dev/null @@ -1,690 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.web.project.ui.customizer; - -import java.awt.Component; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.AbstractListModel; -import javax.swing.ComboBoxModel; -import javax.swing.DefaultListCellRenderer; -import javax.swing.JButton; -import javax.swing.JList; -import javax.swing.ListCellRenderer; -import javax.swing.event.ListDataEvent; -import javax.swing.event.ListDataListener; -import org.netbeans.api.java.platform.JavaPlatform; -import org.netbeans.api.java.platform.JavaPlatformManager; -import org.netbeans.api.java.platform.Specification; -import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; -import org.netbeans.modules.web.project.WebProjectType; -import org.netbeans.modules.web.project.UpdateHelper; -import org.netbeans.spi.project.support.ant.EditableProperties; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.awt.HtmlRenderer; -import org.openide.modules.SpecificationVersion; -import org.openide.util.NbBundle; -import org.openide.util.WeakListeners; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -/** - * Support class for {@link JavaPlatform} manipulation in webproject customizer. - * @author tzezula - */ -public class PlatformUiSupport { - - private static final SpecificationVersion JDK_5 = new SpecificationVersion ("1.5"); //NOI18N - private static final SpecificationVersion JDK_6 = new SpecificationVersion ("1.6"); //NOI18N - private static final Logger LOGGER = Logger.getLogger(PlatformUiSupport.class.getName()); - - private PlatformUiSupport() { - } - - /** - * Creates {@link ComboBoxModel} of J2SE platforms. - * The model listens on the {@link JavaPlatformManager} and update its - * state according to changes - * @param activePlatform the active project's platform - * @return {@link ComboBoxModel} - */ - public static ComboBoxModel createPlatformComboBoxModel (String activePlatform) { - return new PlatformComboBoxModel (activePlatform); - } - - /** - * Creates a {@link ListCellRenderer} for rendering items of the {@link ComboBoxModel} - * created by the {@link PlatformUiSupport#createPlatformComboBoxModel} method. - * @return {@link ListCellRenderer} - */ - public static ListCellRenderer createPlatformListCellRenderer () { - return new PlatformListCellRenderer (); - } - - /** - * Like {@link #storePlatform}, but platformName may be null (in which case the default platform is used) - */ - public static void storePlatform (EditableProperties props, UpdateHelper helper, String platformName, SpecificationVersion sourceLevel) { - PlatformKey platformKey; - if (platformName != null) { - platformKey = new PlatformKey(PlatformUiSupport.findPlatform(platformName)); - } else { - platformKey = new PlatformKey(JavaPlatformManager.getDefault().getDefaultPlatform()); - } - storePlatform(props, helper, platformKey, sourceLevel == null ? null : new SourceLevelKey(sourceLevel)); - } - - /** - * Stores active platform, javac.source and javac.target into the project's metadata - * @param props project's shared properties - * @param helper to read/update project.xml - * @param platformKey the PatformKey got from the platform model - * @param sourceLevel source level - */ - public static void storePlatform (EditableProperties props, UpdateHelper helper, Object platformKey, Object sourceLevelKey) { - assert platformKey instanceof PlatformKey; - PlatformKey pk = (PlatformKey) platformKey; - JavaPlatform platform = getPlatform(pk); - //null means active broken (unresolved) platform, no need to do anything - if (platform != null) { - SpecificationVersion jdk13 = new SpecificationVersion ("1.3"); //NOI18N - String platformAntName = platform.getProperties().get("platform.ant.name"); //NOI18N - assert platformAntName != null; - props.put(WebProjectProperties.JAVA_PLATFORM, platformAntName); - Element root = helper.getPrimaryConfigurationData(true); - boolean defaultPlatform = pk.isDefaultPlatform(); - boolean changed = false; - NodeList explicitPlatformNodes = root.getElementsByTagNameNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"explicit-platform"); //NOI18N - if (defaultPlatform) { - if (explicitPlatformNodes.getLength()==1) { - root.removeChild(explicitPlatformNodes.item(0)); - changed = true; - } - } - else { - Element explicitPlatform; - switch (explicitPlatformNodes.getLength()) { - case 0: - explicitPlatform = root.getOwnerDocument().createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, "explicit-platform"); //NOI18N - NodeList sourceRootNodes = root.getElementsByTagNameNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N - assert sourceRootNodes.getLength() == 1 : "Broken project.xml file"; //NOI18N - root.insertBefore(explicitPlatform, sourceRootNodes.item(0)); - changed = true; - break; - case 1: - explicitPlatform = (Element)explicitPlatformNodes.item(0); - break; - default: - throw new AssertionError("Broken project.xml file"); //NOI18N - } - String explicitSourceAttrValue = explicitPlatform.getAttribute("explicit-source-supported"); //NOI18N - if (jdk13.compareTo(platform.getSpecification().getVersion())>=0 && - !"false".equals(explicitSourceAttrValue)) { //NOI18N - explicitPlatform.setAttribute("explicit-source-supported","false"); //NOI18N - changed = true; - } - else if (jdk13.compareTo(platform.getSpecification().getVersion())<0 && - !"true".equals(explicitSourceAttrValue)) { //NOI18N - explicitPlatform.setAttribute("explicit-source-supported","true"); //NOI18N - changed = true; - } - } - - SpecificationVersion sourceLevel; - if (sourceLevelKey == null) { - sourceLevel = platform.getSpecification().getVersion(); - } - else { - assert sourceLevelKey instanceof SourceLevelKey; - sourceLevel = ((SourceLevelKey)sourceLevelKey).getSourceLevel(); - } - String javacSource = sourceLevel.toString(); - String javacTarget = javacSource; - - //Issue #116490 - // Customizer value | -source | -targer - // JDK 1.2 1.2 1.1 - // JDK 1.3 1.3 1.1 - // JDK 1.4 1.4 1.4 - // JDK 5 1.5 1.5 - // JDK 6 1.5 1.6 - // JDK 7 1.7 1.7 - should bring a new language features - if (jdk13.compareTo(sourceLevel)>=0) { - javacTarget = "1.1"; //NOI18N - } - else if (JDK_6.equals(sourceLevel)) { - javacSource = JDK_5.toString(); //NOI18N - } - - // #89131: these levels are not actually distinct from 1.5. - if (javacSource.equals("1.6") || javacSource.equals("1.7")) { - javacSource = "1.5"; - } - if (!javacSource.equals(props.getProperty(WebProjectProperties.JAVAC_SOURCE))) { - props.setProperty (WebProjectProperties.JAVAC_SOURCE, javacSource); - } - if (!javacTarget.equals(props.getProperty(WebProjectProperties.JAVAC_TARGET))) { - props.setProperty (WebProjectProperties.JAVAC_TARGET, javacTarget); - } - - if (changed) { - helper.putPrimaryConfigurationData(root, true); - } - } - } - - public static JavaPlatform findPlatform(String displayName) { - JavaPlatform[] platforms = JavaPlatformManager.getDefault().getPlatforms(displayName, new Specification("j2se", null)); //NOI18N - return platforms.length == 0 ? null : platforms[0]; - } - - - /** - * Returns a {@link JavaPlatform} for an item obtained from the ComboBoxModel created by - * the {@link PlatformUiSupport#createComboBoxModel} method - * @param platformKey an item obtained from ComboBoxModel created by {@link PlatformUiSupport#createComboBoxModel} - * @return JavaPlatform or null in case when platform is broken - * @exception {@link IllegalArgumentException} is thrown in case when parameter in not an object created by - * platform combobox model. - */ - public static JavaPlatform getPlatform (Object platformKey) { - if (platformKey instanceof PlatformKey) { - return getPlatform ((PlatformKey)platformKey); - } - else { - throw new IllegalArgumentException (); - } - } - - /** - * Creates {@link ComboBoxModel} of source levels for active platform. - * The model listens on the platform's {@link ComboBoxModel} and update its - * state according to changes - * @param platformComboBoxModel the platform's model used for listenning - * @param initialSourceLevel initial source level value - * @param initialTargetLevel initial target level value - * @return {@link ComboBoxModel} of {@link SpecificationVersion} - */ - public static ComboBoxModel createSourceLevelComboBoxModel(ComboBoxModel platformComboBoxModel, String initialSourceLevel, String initialTargetLevel, String j2eePlatform) { - return new SourceLevelComboBoxModel(platformComboBoxModel, initialSourceLevel, initialTargetLevel, j2eePlatform); - } - - public static ListCellRenderer createSourceLevelListCellRenderer() { - return new SourceLevelListCellRenderer(); - } - - private static JavaPlatform getPlatform (PlatformKey platformKey) { - return platformKey.platform; - } - - /** - * This class represents a JavaPlatform in the {@link ListModel} - * created by the {@link PlatformUiSupport#createPlatformComboBoxModel} - * method. - */ - private static class PlatformKey implements Comparable { - - private String name; - private JavaPlatform platform; - - /** - * Creates a PlatformKey for a broken platform - * @param name the ant name of the broken platform - */ - public PlatformKey (String name) { - assert name != null; - this.name = name; - } - - /** - * Creates a PlatformKey for a platform - * @param platform the {@link JavaPlatform} - */ - public PlatformKey (JavaPlatform platform) { - assert platform != null; - this.platform = platform; - } - - public int compareTo(Object o) { - return this.getDisplayName().compareTo(((PlatformKey)o).getDisplayName()); - } - - public boolean equals (Object other) { - if (other instanceof PlatformKey) { - PlatformKey otherKey = (PlatformKey)other; - return (this.platform == null ? otherKey.platform == null : this.platform.equals(otherKey.platform)) && - otherKey.getDisplayName().equals (this.getDisplayName()); - } - else { - return false; - } - } - - public int hashCode () { - return getDisplayName ().hashCode (); - } - - public String toString () { - return getDisplayName (); - } - - public synchronized String getDisplayName () { - if (this.name == null) { - this.name = this.platform.getDisplayName(); - } - return this.name; - } - - public boolean isDefaultPlatform () { - if (this.platform == null) { - return false; - } - return this.platform.equals(JavaPlatformManager.getDefault().getDefaultPlatform()); - } - - public boolean isBroken () { - return this.platform == null; - } - - } - - private static final class SourceLevelKey implements Comparable { - - final SpecificationVersion sourceLevel; - final boolean broken; - - public SourceLevelKey (final SpecificationVersion sourceLevel) { - this (sourceLevel, false); - } - - public SourceLevelKey (final SpecificationVersion sourceLevel, final boolean broken) { - assert sourceLevel != null : "Source level cannot be null"; //NOI18N - this.sourceLevel = sourceLevel; - this.broken = broken; - } - - public SpecificationVersion getSourceLevel () { - return this.sourceLevel; - } - - public boolean isBroken () { - return this.broken; - } - - public int compareTo (final Object other) { - assert other instanceof SourceLevelKey : "Illegal argument of SourceLevelKey.compareTo()"; //NOI18N - SourceLevelKey otherKey = (SourceLevelKey) other; - return this.sourceLevel.compareTo(otherKey.sourceLevel); - } - - public @Override boolean equals (final Object other) { - return (other instanceof SourceLevelKey) && - ((SourceLevelKey)other).sourceLevel.equals(this.sourceLevel); - } - - public @Override int hashCode () { - return this.sourceLevel.hashCode(); - } - - public @Override String toString () { - StringBuffer buffer = new StringBuffer (); - if (this.broken) { - buffer.append("Broken: "); //NOI18N - } - buffer.append(this.sourceLevel.toString()); - return buffer.toString(); - } - - public String getDisplayName () { - String _tmp = sourceLevel.toString(); - if (JDK_5.compareTo(sourceLevel)<=0) { - _tmp = _tmp.replaceFirst("^1\\.([5-9]|\\d\\d+)$", "$1"); //NOI18N - } - return NbBundle.getMessage(PlatformUiSupport.class, "LBL_JDK",_tmp); - } - - } - - private static class PlatformComboBoxModel extends AbstractListModel implements ComboBoxModel, PropertyChangeListener { - - private final JavaPlatformManager pm; - private PlatformKey[] platformNamesCache; - private String initialPlatform; - private PlatformKey selectedPlatform; - - public PlatformComboBoxModel (String initialPlatform) { - this.pm = JavaPlatformManager.getDefault(); - this.pm.addPropertyChangeListener(WeakListeners.propertyChange(this, this.pm)); - this.initialPlatform = initialPlatform; - } - - public int getSize () { - PlatformKey[] platformNames = getPlatformNames (); - return platformNames.length; - } - - public Object getElementAt (int index) { - PlatformKey[] platformNames = getPlatformNames (); - assert index >=0 && index< platformNames.length; - return platformNames[index]; - } - - public Object getSelectedItem () { - this.getPlatformNames(); //Force setting of selectedPlatform if it is not alredy done - return this.selectedPlatform; - } - - public void setSelectedItem (Object obj) { - this.selectedPlatform = (PlatformKey) obj; - this.fireContentsChanged(this, -1, -1); - } - - public void propertyChange (PropertyChangeEvent event) { - if (JavaPlatformManager.PROP_INSTALLED_PLATFORMS.equals(event.getPropertyName())) { - synchronized (this) { - this.platformNamesCache = null; - } - this.fireContentsChanged(this, -1, -1); - } - } - - private synchronized PlatformKey[] getPlatformNames () { - if (this.platformNamesCache == null) { - JavaPlatform[] platforms = pm.getPlatforms (null, new Specification("j2se",null)); //NOI18N - Set/**/ orderedNames = new TreeSet (); - boolean activeFound = false; - for (int i=0; i< platforms.length; i++) { - if (platforms[i].getInstallFolders().size()>0) { - PlatformKey pk = new PlatformKey(platforms[i]); - orderedNames.add (pk); - if (!activeFound && initialPlatform != null) { - String antName = (String) platforms[i].getProperties().get("platform.ant.name"); //NOI18N - if (initialPlatform.equals(antName)) { - if (this.selectedPlatform == null) { - this.selectedPlatform = pk; - initialPlatform = null; - } - activeFound = true; - } - } - } - } - if (!activeFound) { - if (initialPlatform == null) { - if (this.selectedPlatform == null || !orderedNames.contains(this.selectedPlatform)) { - this.selectedPlatform = new PlatformKey (JavaPlatformManager.getDefault().getDefaultPlatform()); - } - } - else { - PlatformKey pk = new PlatformKey (this.initialPlatform); - orderedNames.add (pk); - if (this.selectedPlatform == null) { - this.selectedPlatform = pk; - } - } - } - this.platformNamesCache = (PlatformKey[]) orderedNames.toArray(new PlatformKey[orderedNames.size()]); - } - return this.platformNamesCache; - } - - } - - private static class PlatformListCellRenderer extends DefaultListCellRenderer { - - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - assert value instanceof PlatformKey : "Wrong model"; //NOI18N - PlatformKey key = (PlatformKey) value; - String name; - if (key.isBroken()) { - name = NbBundle.getMessage (PlatformUiSupport.class,"TXT_BrokenPlatformFmt", key.getDisplayName()); - } - else { - name = key.getDisplayName(); - } - return super.getListCellRendererComponent(list, name, index, isSelected, cellHasFocus); - } - } - - private static class SourceLevelComboBoxModel extends AbstractListModel implements ComboBoxModel, ListDataListener { - - private static final String VERSION_PREFIX = "1."; //The version prefix - private static final int INITIAL_VERSION_MINOR = 2; //1.2 - // if project is JAVA EE 5 show only 1.5 and higher - private static final int INITIAL_VERSION_MINOR_JAVA_EE_5 = 5; // 1.5 - - private SpecificationVersion selectedSourceLevel; - private SpecificationVersion originalSourceLevel; - private SourceLevelKey[] sourceLevelCache; - private final ComboBoxModel platformComboBoxModel; - private PlatformKey activePlatform; - private String j2eePlatform = null; - - public SourceLevelComboBoxModel(ComboBoxModel platformComboBoxModel, String initialSourceLevel, String initialTargetLevel) { - this.platformComboBoxModel = platformComboBoxModel; - this.activePlatform = (PlatformKey) this.platformComboBoxModel.getSelectedItem(); - this.platformComboBoxModel.addListDataListener(this); - if (initialSourceLevel != null && initialSourceLevel.length()>0) { - try { - originalSourceLevel = new SpecificationVersion (initialSourceLevel); - } catch (NumberFormatException nfe) { - // If the javac.source has invalid value, do not preselect and log it. - LOGGER.log(Level.INFO, "Invalid javac.source: " + initialSourceLevel); - } - } - if (initialTargetLevel != null && initialTargetLevel.length() > 0) { - try { - SpecificationVersion originalTargetLevel = new SpecificationVersion (initialTargetLevel); - if (this.originalSourceLevel == null || this.originalSourceLevel.compareTo(originalTargetLevel)<0) { - this.originalSourceLevel = originalTargetLevel; - } - } catch (NumberFormatException nfe) { - //If the javac.target has invalid value, do not preselect and log it - LOGGER.warning("Invalid javac.target: "+initialTargetLevel); //NOI18N - } - } - this.selectedSourceLevel = this.originalSourceLevel; - } - - public SourceLevelComboBoxModel(ComboBoxModel platformComboBoxModel, String initialSourceLevel, String initialTargetLevel, String j2eePlatform) { - this(platformComboBoxModel, initialSourceLevel, initialTargetLevel); - this.j2eePlatform = j2eePlatform; - } - - public int getSize() { - SourceLevelKey[] sLevels = getSourceLevels(); - return sLevels.length; - } - - public Object getElementAt(int index) { - SourceLevelKey[] sLevels = getSourceLevels(); - assert index >=0 && index< sLevels.length; - return sLevels[index]; - } - - public Object getSelectedItem () { - SourceLevelKey[] keys = getSourceLevels(); - for (int i=0; i0 && - !shouldChangePlatform(selectedSourceLevel, version)) { - //Restore original - this.platformComboBoxModel.setSelectedItem(this.activePlatform); - return; - } - else { - this.originalSourceLevel = null; - } - } - this.activePlatform = selectedPlatform; - resetCache(); - } - - private void resetCache() { - synchronized (this) { - this.sourceLevelCache = null; - } - this.fireContentsChanged(this, -1, -1); - } - - private SourceLevelKey[] getSourceLevels() { - if (this.sourceLevelCache == null) { - PlatformKey selectedPlatform = (PlatformKey) this.platformComboBoxModel.getSelectedItem(); - JavaPlatform platform = getPlatform(selectedPlatform); - List sLevels = new ArrayList(); - //If platform == null broken platform, the source level range is unknown - //The source level combo box should be empty and disabled - boolean selSourceLevelValid = false; - if (platform != null) { - SpecificationVersion version = platform.getSpecification().getVersion(); - int index = INITIAL_VERSION_MINOR; - // #71619 - source level lower than 1.5 won't be shown for Java EE 5 project - if (j2eePlatform != null && j2eePlatform.equals(J2eeModule.JAVA_EE_5)) { - index = INITIAL_VERSION_MINOR_JAVA_EE_5; - } - SpecificationVersion template = new SpecificationVersion (VERSION_PREFIX + Integer.toString (index++)); - boolean origSourceLevelValid = false; - - while (template.compareTo(version)<=0) { - if (template.equals(this.originalSourceLevel)) { - origSourceLevelValid = true; - } - if (template.equals(this.selectedSourceLevel)) { - selSourceLevelValid = true; - } - sLevels.add (new SourceLevelKey (template)); - template = new SpecificationVersion (VERSION_PREFIX + Integer.toString (index++)); - } - if (this.originalSourceLevel != null && !origSourceLevelValid) { - if (originalSourceLevel.equals(this.selectedSourceLevel)) { - selSourceLevelValid = true; - } - sLevels.add (new SourceLevelKey(this.originalSourceLevel,true)); - } - } - this.sourceLevelCache = sLevels.toArray(new SourceLevelKey[sLevels.size()]); - if (!selSourceLevelValid) { - this.selectedSourceLevel = this.sourceLevelCache.length == 0 ? - null : this.sourceLevelCache[this.sourceLevelCache.length-1].getSourceLevel(); - } - } - return this.sourceLevelCache; - } - - private static boolean shouldChangePlatform (SpecificationVersion selectedSourceLevel, SpecificationVersion platformSourceLevel) { - JButton changeOption = new JButton (NbBundle.getMessage(PlatformUiSupport.class, "CTL_ChangePlatform")); - changeOption.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PlatformUiSupport.class, "AD_ChangePlatform")); - String message = MessageFormat.format (NbBundle.getMessage(PlatformUiSupport.class,"TXT_ChangePlatform"),new Object[] { - selectedSourceLevel.toString(), - platformSourceLevel.toString(), - }); - return DialogDisplayer.getDefault().notify( - new NotifyDescriptor (message, - NbBundle.getMessage(PlatformUiSupport.class,"TXT_ChangePlatformTitle"), - NotifyDescriptor.DEFAULT_OPTION, - NotifyDescriptor.WARNING_MESSAGE, - new Object[] { - changeOption, - NotifyDescriptor.CANCEL_OPTION - }, - changeOption)) == changeOption; - } - } - - private static class SourceLevelListCellRenderer implements ListCellRenderer { - - ListCellRenderer delegate; - - public SourceLevelListCellRenderer() { - this.delegate = HtmlRenderer.createRenderer(); - } - - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - String message; - if (value == null) { - message = ""; //NOI18N - } - else { - assert value instanceof SourceLevelKey; - SourceLevelKey key = (SourceLevelKey) value; - if (key.isBroken()) { - message = "" + //NOI18N - NbBundle.getMessage(PlatformUiSupport.class,"TXT_InvalidSourceLevel",key.getDisplayName()); - } - else { - message = key.getDisplayName(); - } - } - return this.delegate.getListCellRendererComponent(list, message, index, isSelected, cellHasFocus); - } - } -} diff --git a/web.project/src/org/netbeans/modules/web/project/ui/customizer/WebProjectProperties.java b/web.project/src/org/netbeans/modules/web/project/ui/customizer/WebProjectProperties.java --- a/web.project/src/org/netbeans/modules/web/project/ui/customizer/WebProjectProperties.java +++ b/web.project/src/org/netbeans/modules/web/project/ui/customizer/WebProjectProperties.java @@ -65,14 +65,12 @@ import org.netbeans.modules.j2ee.deploym import org.netbeans.modules.j2ee.deployment.devmodules.api.AntDeploymentHelper; import org.netbeans.modules.web.project.ProjectWebModule; -import org.netbeans.modules.web.project.SourceRoots; import org.netbeans.modules.web.project.classpath.ClassPathSupport; import org.netbeans.modules.web.spi.webmodule.WebModuleExtender; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.ui.StoreGroup; import org.openide.filesystems.FileUtil; -import org.openide.modules.SpecificationVersion; import org.openide.util.MutexException; import org.openide.util.Mutex; import org.netbeans.api.project.Project; @@ -82,16 +80,19 @@ import org.netbeans.modules.j2ee.deploym import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; +import org.netbeans.modules.java.api.common.SourceRoots; +import org.netbeans.modules.java.api.common.ant.UpdateHelper; +import org.netbeans.modules.java.api.common.ui.PlatformUiSupport; +import org.netbeans.modules.web.project.UpdateProjectImpl; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.EditableProperties; import org.netbeans.spi.project.support.ant.PropertyUtils; import org.netbeans.spi.project.support.ant.ReferenceHelper; import org.netbeans.modules.web.project.WebProjectUtil; -import org.netbeans.modules.web.project.UpdateHelper; import org.netbeans.modules.web.project.Utils; import org.netbeans.modules.web.project.WebProject; +import org.netbeans.modules.web.project.WebProjectType; import org.netbeans.modules.web.project.classpath.ClassPathSupport.Item; -import org.netbeans.modules.web.spi.webmodule.WebFrameworkProvider; import org.netbeans.modules.websvc.spi.webservices.WebServicesConstants; import org.openide.filesystems.FileObject; import org.openide.filesystems.URLMapper; @@ -292,7 +293,7 @@ public class WebProjectProperties { this.updateHelper = updateHelper; //this is called from updatehelper when user confirms the project update - updateHelper.setProjectUpdateListener(new UpdateHelper.ProjectUpdateListener() { + project.getUpdateImplementation().setProjectUpdateListener(new UpdateProjectImpl.ProjectUpdateListener() { public void projectUpdated() { needsUpdate = true; } @@ -337,7 +338,11 @@ public class WebProjectProperties { RUN_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String)projectProperties.get( RUN_TEST_CLASSPATH ), null ) ); PLATFORM_MODEL = PlatformUiSupport.createPlatformComboBoxModel (evaluator.getProperty(JAVA_PLATFORM)); PLATFORM_LIST_RENDERER = PlatformUiSupport.createPlatformListCellRenderer(); - JAVAC_SOURCE_MODEL = PlatformUiSupport.createSourceLevelComboBoxModel (PLATFORM_MODEL, evaluator.getProperty(JAVAC_SOURCE), evaluator.getProperty(JAVAC_TARGET), evaluator.getProperty(J2EE_PLATFORM)); + PlatformUiSupport.JDK minimalSourceLevel = null; + if (evaluator.getProperty(J2EE_PLATFORM).equals(J2eeModule.JAVA_EE_5)) { + minimalSourceLevel = PlatformUiSupport.JDK.VERSION_5; + } + JAVAC_SOURCE_MODEL = PlatformUiSupport.createSourceLevelComboBoxModel (PLATFORM_MODEL, evaluator.getProperty(JAVAC_SOURCE), evaluator.getProperty(JAVAC_TARGET), minimalSourceLevel); JAVAC_SOURCE_RENDERER = PlatformUiSupport.createSourceLevelListCellRenderer (); // CustomizerCompile @@ -530,7 +535,7 @@ public class WebProjectProperties { projectProperties.setProperty( WAR_CONTENT_ADDITIONAL, war_includes ); //Handle platform selection and javac.source javac.target properties - PlatformUiSupport.storePlatform (projectProperties, updateHelper, PLATFORM_MODEL.getSelectedItem(), JAVAC_SOURCE_MODEL.getSelectedItem()); + PlatformUiSupport.storePlatform (projectProperties, updateHelper, WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, PLATFORM_MODEL.getSelectedItem(), JAVAC_SOURCE_MODEL.getSelectedItem()); // Handle other special cases if ( NO_DEPENDENCIES_MODEL.isSelected() ) { // NOI18N diff --git a/web.project/src/org/netbeans/modules/web/project/ui/customizer/WebSourceRootsUi.java b/web.project/src/org/netbeans/modules/web/project/ui/customizer/WebSourceRootsUi.java --- a/web.project/src/org/netbeans/modules/web/project/ui/customizer/WebSourceRootsUi.java +++ b/web.project/src/org/netbeans/modules/web/project/ui/customizer/WebSourceRootsUi.java @@ -64,7 +64,7 @@ import org.netbeans.api.project.FileOwne import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectInformation; -import org.netbeans.modules.web.project.SourceRoots; +import org.netbeans.modules.java.api.common.SourceRoots; import org.openide.DialogDisplayer; import org.openide.DialogDescriptor; import org.openide.filesystems.FileUtil; diff --git a/web.project/test/unit/src/org/netbeans/modules/web/project/SourceRootsTest.java b/web.project/test/unit/src/org/netbeans/modules/web/project/SourceRootsTest.java --- a/web.project/test/unit/src/org/netbeans/modules/web/project/SourceRootsTest.java +++ b/web.project/test/unit/src/org/netbeans/modules/web/project/SourceRootsTest.java @@ -53,6 +53,7 @@ import org.netbeans.junit.NbTestCase; import org.netbeans.junit.NbTestCase; import org.netbeans.api.project.ProjectManager; import org.netbeans.api.project.Project; +import org.netbeans.modules.java.api.common.SourceRoots; import org.netbeans.modules.web.project.test.TestBase; import org.netbeans.modules.web.project.test.TestUtil; import org.netbeans.spi.project.support.ant.AntProjectHelper;