# HG changeset patch # User Martin Kozeny # Date 1366124955 -7200 # Node ID debe75cafdf729bc87eec4637dd033442c7af1cc # Parent 2eebfa32871b064fd741310124811b75012d03d7 #228409: "Export Package" function is now provided as an API. Now is possible to implement interface PackageModifierImplementation for particular project. diff --git a/apisupport.ant/nbproject/project.xml b/apisupport.ant/nbproject/project.xml --- a/apisupport.ant/nbproject/project.xml +++ b/apisupport.ant/nbproject/project.xml @@ -355,6 +355,10 @@ + org.netbeans.libs.testng + + + org.netbeans.modules.apisupport.ant diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/NbModuleProject.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/NbModuleProject.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/NbModuleProject.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/NbModuleProject.java @@ -102,6 +102,7 @@ import org.netbeans.modules.apisupport.project.ui.ModuleLogicalView; import org.netbeans.modules.apisupport.project.ui.ModuleOperations; import org.netbeans.modules.apisupport.project.ui.customizer.CustomizerProviderImpl; +import org.netbeans.modules.apisupport.project.ui.customizer.NbModulePackageModifierImplementation; import org.netbeans.modules.apisupport.project.ui.customizer.SingleModuleProperties; import org.netbeans.modules.apisupport.project.ui.customizer.SuiteProperties; import org.netbeans.modules.apisupport.project.universe.HarnessVersion; @@ -312,6 +313,7 @@ ic.add(new SourceLevelQueryImpl(this)); //ic.add(new ProjectWhiteListQueryImplementation(this)); ic.add(new ProjectWhiteListQueryImplementation(this)); + ic.add(new NbModulePackageModifierImplementation(this)); ic.add(helper.createSharabilityQuery2(evaluator(), new String[0], new String[]{ "${build.dir}", // NOI18N })); diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/customizer/ExportPackageAction.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/customizer/ExportPackageAction.java deleted file mode 100644 --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/customizer/ExportPackageAction.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2013 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle 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 2013 Sun Microsystems, Inc. - */ -package org.netbeans.modules.apisupport.project.ui.customizer; - -import java.awt.event.ActionEvent; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.SortedSet; -import javax.swing.AbstractAction; -import javax.swing.Action; -import org.netbeans.api.project.FileOwnerQuery; -import org.netbeans.api.project.Project; -import org.netbeans.api.project.ProjectManager; -import org.netbeans.modules.apisupport.project.ApisupportAntUtils; -import org.netbeans.modules.apisupport.project.NbModuleProject; -import org.openide.ErrorManager; -import org.openide.awt.ActionID; -import org.openide.awt.ActionReference; -import org.openide.awt.ActionReferences; -import org.openide.awt.ActionRegistration; -import org.openide.awt.DynamicMenuContent; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.util.ContextAwareAction; -import org.openide.util.Lookup; -import org.openide.util.Mutex; -import org.openide.util.MutexException; -import org.openide.util.NbBundle.Messages; - -/** - * Submenu which permits the user to export or unexport appropriate package. - * Must be locate in NetBeans Module Project. - */ -@ActionID( - category = "Project", - id = "org.netbeans.modules.apisupport.project.ExportPackageAction") -@ActionRegistration( - displayName = "#CTL_ExportPackageAction", lazy = false) -@ActionReferences({ - @ActionReference(path = "Projects/package/Actions", position = 100), -}) -@Messages({"CTL_UnexportPackageAction=Unexport Package","CTL_ExportPackageAction=Export Package"}) -public final class ExportPackageAction extends AbstractAction implements ContextAwareAction{ - - @Override - public void actionPerformed(ActionEvent ev) { - //well, since someone can assign a shortcut ti the action, the invokation is unvaiodable, make it noop - //assert false : "Action should never be called without a context"; - } - - @Override - public Action createContextAwareInstance(Lookup actionContext) { - Collection selectedPackages = (Collection) actionContext.lookupAll(FileObject.class); - Project project = FileOwnerQuery.getOwner(selectedPackages.iterator().hasNext()?selectedPackages.iterator().next():null); - NbModuleProject nbmProject = null; - if((nbmProject = project.getLookup().lookup(NbModuleProject.class)) != null) - { - Collection packages = new ArrayList(); - SortedSet availablePublicPackages = ApisupportAntUtils.scanProjectForPackageNames(FileUtil.toFile(nbmProject.getProjectDirectory()), false); - final SingleModuleProperties properties = SingleModuleProperties.getInstance(nbmProject); - String packageNameIter = ""; - boolean export = false; - for (Iterator it = selectedPackages.iterator(); it.hasNext();) { - FileObject packageIter = it.next(); - if(!availablePublicPackages.contains(packageNameIter = packageIter.getPath().substring(nbmProject.getSourceDirectory().getPath().length()+1).replace('/', '.'))) { - continue; - } - packages.add(packageNameIter); - if(!properties.getPublicPackagesModel().getSelectedPackages().contains(packageNameIter) && !export) { - export = true; - } - } - return new ContextAction(!packages.isEmpty(), nbmProject, packages, properties, export); - } - return new ContextAction(false); - } - - /** - * The particular instance of this action for a given package(s). - */ - private static final class ContextAction extends AbstractAction { - - private NbModuleProject nbmProject; - - private final SingleModuleProperties properties; - - private Collection packages; - - private boolean export; - - public ContextAction(boolean enabled) { - this(enabled, null, null, null, true); - } - - public ContextAction(boolean enabled, NbModuleProject nbmProject, Collection packages, SingleModuleProperties properties, boolean export) { - super(export?Bundle.CTL_ExportPackageAction():Bundle.CTL_UnexportPackageAction()); - this.nbmProject = nbmProject; - this.packages = packages; - this.properties = properties; - this.export = export; - this.putValue(DynamicMenuContent.HIDE_WHEN_DISABLED, true); - this.setEnabled(enabled); - } - - @Override - public void actionPerformed(ActionEvent evt) { - CustomizerComponentFactory.PublicPackagesTableModel tableModel = properties.getPublicPackagesModel(); - for(String packageIter:this.packages) { - for(int i = 0; i < tableModel.getRowCount(); i++) { - if(tableModel.getValueAt(i, 1).equals(packageIter)) { - tableModel.setValueAt(this.export, i, 0); - break; - } - } - } - try { - ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() { - @Override public Void run() throws IOException { - properties.storeProperties(); - ProjectManager.getDefault().saveProject(nbmProject); - return null; - } - }); - } catch (MutexException e) { - ErrorManager.getDefault().notify((IOException)e.getException()); - } - } - - } -} \ No newline at end of file diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/customizer/NbModulePackageModifierImplementation.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/customizer/NbModulePackageModifierImplementation.java new file mode 100644 --- /dev/null +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/customizer/NbModulePackageModifierImplementation.java @@ -0,0 +1,116 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.apisupport.project.ui.customizer; + +import java.io.IOException; +import java.util.Collection; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.modules.apisupport.project.ApisupportAntUtils; +import org.netbeans.modules.apisupport.project.NbModuleProject; +import org.netbeans.modules.java.api.common.ant.PackageModifierImplementation; +import org.openide.ErrorManager; +import org.openide.filesystems.FileUtil; +import org.openide.util.Mutex; +import org.openide.util.MutexException; + +/** + * + * @author mkozeny + */ + +//@ProjectServiceProvider(service = PackageModifierImplementation.class) +public final class NbModulePackageModifierImplementation implements PackageModifierImplementation{ + + private final NbModuleProject project; + + /** + * Constructor + * @param project + */ + public NbModulePackageModifierImplementation(NbModuleProject project) { + this.project = project; + } + + @Override + public Collection getAllPackages() { + if(this.project != null) { + return ApisupportAntUtils.scanProjectForPackageNames(FileUtil.toFile(this.project.getProjectDirectory()), false); + } + return null; + } + + @Override + public Collection getPublicPackages() { + if(this.project != null) { + final SingleModuleProperties properties = SingleModuleProperties.getInstance(this.project); + return properties.getPublicPackagesModel().getSelectedPackages(); + } + return null; + } + + @Override + public void exportPackageAction(Collection packagesToExport, boolean export) { + final SingleModuleProperties properties = SingleModuleProperties.getInstance(this.project); + CustomizerComponentFactory.PublicPackagesTableModel tableModel = properties.getPublicPackagesModel(); + for(String packageIter:packagesToExport) { + for(int i = 0; i < tableModel.getRowCount(); i++) { + if(tableModel.getValueAt(i, 1).equals(packageIter)) { + tableModel.setValueAt(export, i, 0); + break; + } + } + } + final NbModuleProject nbmProject = this.project; + try { + ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() { + @Override public Void run() throws IOException { + properties.storeProperties(); + ProjectManager.getDefault().saveProject(nbmProject); + return null; + } + }); + } catch (MutexException e) { + ErrorManager.getDefault().notify((IOException)e.getException()); + } + } + +} diff --git a/java.api.common/apichanges.xml b/java.api.common/apichanges.xml --- a/java.api.common/apichanges.xml +++ b/java.api.common/apichanges.xml @@ -105,6 +105,25 @@ + + + New API PackageModificationImplementation + + + + + +

+ Added new API PackageModificationImplementation, which provides methods + for getting all available packages (getPackagesToExport) + and all public packages (getPublicPackages), + (un)exporting them (exportPackageAction). + This API is used by ExportPackageAction located in non-public package org.netbeans.modules.java.api.common.impl + which is action implemented for exporting package(s) from NetBeans Module Project. +

+
+ +
Added UI support for JRE profiles. diff --git a/java.api.common/manifest.mf b/java.api.common/manifest.mf --- a/java.api.common/manifest.mf +++ b/java.api.common/manifest.mf @@ -1,4 +1,4 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.java.api.common/0 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/api/common/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 1.46 +OpenIDE-Module-Specification-Version: 1.47 diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/ant/PackageModifierImplementation.java b/java.api.common/src/org/netbeans/modules/java/api/common/ant/PackageModifierImplementation.java new file mode 100644 --- /dev/null +++ b/java.api.common/src/org/netbeans/modules/java/api/common/ant/PackageModifierImplementation.java @@ -0,0 +1,73 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.java.api.common.ant; + +import java.util.Collection; +import org.netbeans.api.annotations.common.NonNull; + +/** + * Provide API for manipulating with project packages. + * @author mkozeny + * @since 1.47 + */ +public interface PackageModifierImplementation { + + /** + * Returns collection of all available packages to export or to unexport + * @return collection of all packages which are possible to export or to unexport + */ + public @NonNull Collection getAllPackages(); + + /** + * Returns collection of public packages + * @return collection of public packages + */ + public @NonNull Collection getPublicPackages(); + + /** + * Do the export or unexport of passed set of packages + * @param packagesToExport set of packages to export or to unexport + * @param export whether passed set of packages should be export or unexport + */ + public void exportPackageAction(@NonNull Collection packagesToExport, boolean export); + +} diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/impl/ExportPackageAction.java b/java.api.common/src/org/netbeans/modules/java/api/common/impl/ExportPackageAction.java new file mode 100644 --- /dev/null +++ b/java.api.common/src/org/netbeans/modules/java/api/common/impl/ExportPackageAction.java @@ -0,0 +1,165 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.java.api.common.impl; + +import java.awt.event.ActionEvent; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import javax.swing.AbstractAction; +import javax.swing.Action; +import org.netbeans.api.project.FileOwnerQuery; +import org.netbeans.api.project.Project; +import org.netbeans.modules.java.api.common.ant.PackageModifierImplementation; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.awt.DynamicMenuContent; +import org.openide.filesystems.FileObject; +import org.openide.util.ContextAwareAction; +import org.openide.util.Lookup; +import org.openide.util.NbBundle.Messages; + +/** + * Submenu which permits the user to export or unexport appropriate package. + * Must be locate in NetBeans Module Project. + */ +@ActionID( + category = "Project", + id = "org.netbeans.modules.apisupport.project.ExportPackageAction") +@ActionRegistration( + displayName = "#CTL_ExportPackageAction", lazy = false) +@ActionReferences({ + @ActionReference(path = "Projects/package/Actions", position = 100), +}) +@Messages({"CTL_UnexportPackageAction=Unexport Package","CTL_ExportPackageAction=Export Package"}) +public final class ExportPackageAction extends AbstractAction implements ContextAwareAction{ + + @Override + public void actionPerformed(ActionEvent ev) { + //well, since someone can assign a shortcut ti the action, the invokation is unvaiodable, make it noop + //assert false : "Action should never be called without a context"; + } + + @Override + public Action createContextAwareInstance(Lookup actionContext) { + if(actionContext != null) { + Collection selectedPackagesLookup = actionContext.lookupAll(FileObject.class); + Collection selectedPackages = new ArrayList<>(); + for(FileObject packageIter:selectedPackagesLookup) { + selectedPackages.add(packageIter); + } + Iterator selectedPackagesIterator = selectedPackages.iterator(); + Project project = null; + if(selectedPackagesIterator.hasNext()) { + project = FileOwnerQuery.getOwner(selectedPackagesIterator.next()); + if(project != null) { + while(selectedPackagesIterator.hasNext()) { + Project tmpProject = FileOwnerQuery.getOwner(selectedPackagesIterator.next()); + if(!project.equals(tmpProject)) { + return new ExportPackageAction.ContextAction(); + } + } + } else { + return new ExportPackageAction.ContextAction(); + } + } + PackageModifierImplementation pmi = null; + if((pmi = project.getLookup().lookup(PackageModifierImplementation.class)) != null) { + Collection allPackages = pmi.getAllPackages(); + Collection packagesToExport = new ArrayList<>(); + String selectedPackageNameIter = ""; + for(FileObject selectedPkgIter:selectedPackages) { + if(allPackages.contains( + selectedPackageNameIter = selectedPkgIter.getPath() + .substring(project.getProjectDirectory().getPath().length()+5).replace('/', '.'))) { + packagesToExport.add(selectedPackageNameIter); + } + } + Collection publicPackages = pmi.getPublicPackages(); + boolean export = false; + for(String exportPkgIter:packagesToExport) { + if(!publicPackages.contains(exportPkgIter)) { + export = true; + break; + } + } + return new ExportPackageAction.ContextAction(pmi, packagesToExport, export); + } + } + return new ExportPackageAction.ContextAction(); + } + + /** + * The particular instance of this action for a given package(s). + */ + private static final class ContextAction extends AbstractAction { + + private Collection packagesToExport; + private boolean export; + private PackageModifierImplementation pmi; + + public ContextAction() { + this(true, false); + } + + public ContextAction(PackageModifierImplementation pmi, Collection packagesToExport, boolean export) { + this(export, packagesToExport!=null && !packagesToExport.isEmpty()); + this.pmi = pmi; + this.packagesToExport = packagesToExport; + this.export = export; + } + + private ContextAction(boolean export, boolean enable) { + super(export?Bundle.CTL_ExportPackageAction():Bundle.CTL_UnexportPackageAction()); + this.putValue(DynamicMenuContent.HIDE_WHEN_DISABLED, true); + this.setEnabled(enable); + } + + @Override + public void actionPerformed(ActionEvent evt) { + pmi.exportPackageAction(packagesToExport, export); + } + + } +} \ No newline at end of file