Index: ant/project/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java =================================================================== RCS file: /cvs/ant/project/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java,v retrieving revision 1.8 diff -u -r1.8 AntProjectHelper.java --- ant/project/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java 29 Apr 2004 16:45:22 -0000 1.8 +++ ant/project/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java 30 Apr 2004 10:14:16 -0000 @@ -44,6 +44,7 @@ import org.netbeans.spi.project.CacheDirectoryProvider; import org.netbeans.spi.project.ProjectState; import org.netbeans.spi.queries.FileBuiltQueryImplementation; +import org.netbeans.spi.queries.FileEncodingQueryImplementation; import org.netbeans.spi.queries.SharabilityQueryImplementation; import org.openide.ErrorManager; import org.openide.filesystems.FileLock; @@ -990,4 +991,28 @@ return PropertyUtils.resolvePath(FileUtil.toFile(dir), path); } + /** + * Creates simple implementation of + * {@link org.netbeans.spi.queries.FileEncodingQueryImplementation} returning + * file encoding of project's files. It can be put only into project's + * lookup, because it assumes that file passed to the query belongs to the + * project. + *

The implementation uses given PropertyEvaluator and does following + * in this order: + *

    + *
  1. checks for property encoding.<file_extension> and + * returns that value if presented
  2. + *
  3. checks for property encoding and + * returns that value if presented
  4. + *
  5. returns value of system property file.encoding
  6. + *
+ * This allows to set global encoding for all project files and also per + * file type specific encoding. + * @param evaluator property evaluator of project's properties + * @return implementation of query which can be added to project's lookup + */ + public FileEncodingQueryImplementation createSimpleFileEncodingQuery(PropertyEvaluator evaluator) { + return new SimpleFileEncodingQueryImpl(evaluator); + } + } Index: ant/project/src/org/netbeans/spi/project/support/ant/SimpleFileEncodingQueryImpl.java =================================================================== RCS file: ant/project/src/org/netbeans/spi/project/support/ant/SimpleFileEncodingQueryImpl.java diff -N ant/project/src/org/netbeans/spi/project/support/ant/SimpleFileEncodingQueryImpl.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ant/project/src/org/netbeans/spi/project/support/ant/SimpleFileEncodingQueryImpl.java 30 Apr 2004 10:14:17 -0000 @@ -0,0 +1,51 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package org.netbeans.spi.project.support.ant; + +import java.beans.PropertyChangeListener; +import java.net.URI; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import org.netbeans.api.project.FileOwnerQuery; +import org.netbeans.api.project.Project; +import org.netbeans.spi.queries.FileEncodingQueryImplementation; +import org.openide.filesystems.FileObject; + +/** + * Simple file encoding query based on Ant properties. See + * {@link AntProjectHelper#createSimpleFileEncodingQuery} for more details. + * @author David Konecny + */ +final class SimpleFileEncodingQueryImpl implements FileEncodingQueryImplementation { + + private static final String ENCODING_PREFIX = "encoding"; + + private PropertyEvaluator evaluator; + + public SimpleFileEncodingQueryImpl(PropertyEvaluator evaluator) { + this.evaluator = evaluator; + } + + public String getFileEncoding(FileObject file) { + String res = evaluator.getProperty(ENCODING_PREFIX+"."+file.getExt()); + if (res == null) { + res = evaluator.getProperty(ENCODING_PREFIX); + } + if (res == null) { + res = System.getProperty("file.encoding"); + } + return res; + } + +} Index: ant/project/test/unit/src/org/netbeans/spi/project/support/ant/AntBasedTestUtil.java =================================================================== RCS file: /cvs/ant/project/test/unit/src/org/netbeans/spi/project/support/ant/AntBasedTestUtil.java,v retrieving revision 1.8 diff -u -r1.8 AntBasedTestUtil.java --- ant/project/test/unit/src/org/netbeans/spi/project/support/ant/AntBasedTestUtil.java 30 Apr 2004 04:22:08 -0000 1.8 +++ ant/project/test/unit/src/org/netbeans/spi/project/support/ant/AntBasedTestUtil.java 30 Apr 2004 10:14:18 -0000 @@ -126,6 +126,7 @@ genFilesHelper, aux, helper.createCacheDirectoryProvider(), + helper.createSimpleFileEncodingQuery(helper.getStandardPropertyEvaluator()), refHelper.createSubprojectProvider(), new TestAntArtifactProvider(), new ProjectXmlSavedHook() { Index: ant/project/test/unit/src/org/netbeans/spi/project/support/ant/SimpleFileEncodingQueryImplTest.java =================================================================== RCS file: ant/project/test/unit/src/org/netbeans/spi/project/support/ant/SimpleFileEncodingQueryImplTest.java diff -N ant/project/test/unit/src/org/netbeans/spi/project/support/ant/SimpleFileEncodingQueryImplTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ant/project/test/unit/src/org/netbeans/spi/project/support/ant/SimpleFileEncodingQueryImplTest.java 30 Apr 2004 10:14:18 -0000 @@ -0,0 +1,143 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.spi.project.support.ant; + +import java.io.File; +import java.net.URI; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.api.project.TestUtil; +import org.netbeans.api.project.ant.AntArtifact; +import org.netbeans.api.queries.FileEncodingQuery; +import org.netbeans.junit.NbTestCase; +import org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton; +import org.netbeans.modules.project.ant.FileEncodingQueryImpl; +import org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.filesystems.Repository; +import org.openide.util.Lookup; +import org.openide.util.lookup.Lookups; + +/** + * Tests for SimpleFileEncodingQueryImpl + * + * @author David Konecny + */ +public class SimpleFileEncodingQueryImplTest extends NbTestCase { + + public SimpleFileEncodingQueryImplTest(java.lang.String testName) { + super(testName); + } + + private FileObject scratch; + private FileObject projdir; + private AntProjectHelper helper; + + protected void setUp() throws Exception { + super.setUp(); + scratch = TestUtil.makeScratchDir(this); + Repository.getDefault().addFileSystem(scratch.getFileSystem()); // so FileUtil.fromFile works + TestUtil.setLookup(Lookups.fixed(new Object[] { + new AntBasedProjectFactorySingleton(), + AntBasedTestUtil.testAntBasedProjectType(), + new FileEncodingQueryImpl(), + new SimpleFileOwnerQueryImplementation(), + })); + projdir = FileUtil.createFolder(scratch, "proj"); + helper = ProjectGenerator.createProject(projdir, "test", "proj"); + } + + protected void tearDown() throws Exception { + Repository.getDefault().removeFileSystem(scratch.getFileSystem()); + scratch = null; + projdir = null; + TestUtil.setLookup(Lookup.EMPTY); + super.tearDown(); + } + + public void testGetFileEncoding() throws Exception { + FileObject foreign = scratch.createData("some.file"); + String enc = FileEncodingQuery.getFileEncoding(foreign); + assertEquals("Non-project file must have no encoding", null, enc); + FileObject foreign2 = scratch.createFolder("sub").createData("some.java"); + enc = FileEncodingQuery.getFileEncoding(foreign2); + assertEquals("Non-project file must have no encoding", null, enc); + + String OSEncoding = System.getProperty("file.encoding"); + FileObject projFile = projdir.createData("some.file"); + enc = FileEncodingQuery.getFileEncoding(projFile); + assertEquals("Project file must have system encoding", OSEncoding, enc); + FileObject projFile2 = projdir.createFolder("sub").createData("some.java"); + enc = FileEncodingQuery.getFileEncoding(projFile2); + assertEquals("Project file must have system encoding", OSEncoding, enc); + + // configure encoding for .java files: + EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + ep.setProperty("encoding.java", "SOME.ENCODING.1"); + helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); + enc = FileEncodingQuery.getFileEncoding(projFile2); + assertEquals("Project file must have correct encoding", "SOME.ENCODING.1", enc); + enc = FileEncodingQuery.getFileEncoding(projFile); + assertEquals("Project file must have system encoding", OSEncoding, enc); + + // configure encoding for .file files: + ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + ep.setProperty("encoding.file", "some.THING.else"); + helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); + enc = FileEncodingQuery.getFileEncoding(projFile2); + assertEquals("Project file must have correct encoding", "SOME.ENCODING.1", enc); + enc = FileEncodingQuery.getFileEncoding(projFile); + assertEquals("Project file must have correct encoding", "some.THING.else", enc); + + // non-project files must still have not encoding + enc = FileEncodingQuery.getFileEncoding(foreign); + assertEquals("Non-project file must have no encoding", null, enc); + enc = FileEncodingQuery.getFileEncoding(foreign2); + assertEquals("Non-project file must have no encoding", null, enc); + + // test newly created java file must + FileObject projFile3 = projdir.getFileObject("sub").createFolder("2").createData("foo.java"); + enc = FileEncodingQuery.getFileEncoding(projFile3); + assertEquals("Project file must have correct encoding", "SOME.ENCODING.1", enc); + + // remove some encodings + ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + ep.remove("encoding.file"); + helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); + enc = FileEncodingQuery.getFileEncoding(projFile); + assertEquals("Project file must have system encoding", OSEncoding, enc); + enc = FileEncodingQuery.getFileEncoding(projFile2); + assertEquals("Project file must have correct encoding", "SOME.ENCODING.1", enc); + enc = FileEncodingQuery.getFileEncoding(projFile3); + assertEquals("Project file must have correct encoding", "SOME.ENCODING.1", enc); + + // set default encoding for all files + ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + ep.setProperty("encoding", "UTF-8"); + helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); + enc = FileEncodingQuery.getFileEncoding(projFile); + assertEquals("Project file must have system encoding", "UTF-8", enc); + enc = FileEncodingQuery.getFileEncoding(projFile2); + assertEquals("Project file must have correct encoding", "SOME.ENCODING.1", enc); + enc = FileEncodingQuery.getFileEncoding(projFile3); + assertEquals("Project file must have correct encoding", "SOME.ENCODING.1", enc); + + // non-project files must still have not encoding + enc = FileEncodingQuery.getFileEncoding(foreign); + assertEquals("Non-project file must have no encoding", null, enc); + enc = FileEncodingQuery.getFileEncoding(foreign2); + assertEquals("Non-project file must have no encoding", null, enc); + } + +} Index: apisupport/project/src/org/netbeans/modules/apisupport/project/NbModuleProject.java =================================================================== RCS file: /cvs/apisupport/project/src/org/netbeans/modules/apisupport/project/NbModuleProject.java,v retrieving revision 1.38 diff -u -r1.38 NbModuleProject.java --- apisupport/project/src/org/netbeans/modules/apisupport/project/NbModuleProject.java 30 Apr 2004 04:22:08 -0000 1.38 +++ apisupport/project/src/org/netbeans/modules/apisupport/project/NbModuleProject.java 30 Apr 2004 10:14:21 -0000 @@ -119,6 +119,7 @@ new UnitTestForSourceQueryImpl(this), new LogicalView(this), new SubprojectProviderImpl(this), + helper.createSimpleFileEncodingQuery(evaluator()), fileBuilt, new AccessibilityQueryImpl(this), new SourceLevelQueryImpl(this, evaluator()), @@ -203,6 +204,7 @@ defaults.put("test.qa-functional.src.dir", "test/qa-functional/src"); // NOI18N defaults.put("build.test.unit.classes.dir", "build/test/unit/classes"); // NOI18N defaults.put("module.classpath", computeModuleClasspath()); + defaults.put("encoding", "UTF-8"); // XXX: Jesse must confirm this line // skip a bunch of properties irrelevant here - NBM stuff, etc. return PropertyUtils.sequentialPropertyEvaluator(predefs, new PropertyProvider[] { PropertyUtils.fixedPropertyProvider(stock), Index: java/j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java =================================================================== RCS file: /cvs/java/j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java,v retrieving revision 1.13 diff -u -r1.13 J2SEProject.java --- java/j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java 30 Apr 2004 04:22:07 -0000 1.13 +++ java/j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java 30 Apr 2004 10:14:24 -0000 @@ -148,6 +148,7 @@ new ProjectXmlSavedHookImpl(), new ProjectOpenedHookImpl(), new UnitTestForSourceQueryImpl(helper, evaluator()), + helper.createSimpleFileEncodingQuery(evaluator()), new SourceLevelQueryImpl(helper, evaluator()), sourcesHelper.createSources(), helper.createSharabilityQuery(evaluator(), new String[] { Index: java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/Bundle.properties =================================================================== RCS file: /cvs/java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/Bundle.properties,v retrieving revision 1.4 diff -u -r1.4 Bundle.properties --- java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/Bundle.properties 25 Apr 2004 23:43:03 -0000 1.4 +++ java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/Bundle.properties 30 Apr 2004 10:14:25 -0000 @@ -27,6 +27,7 @@ LBL_CustomizeGeneral_DisplayName_JLabel=Project Name: LBL_CustomizeGeneral_Platform_JLabel=Java Platform: LBL_CustomizeGeneral_Platform_JButton=Edit... +LBL_CustomizeGeneral_Encoding_JLabel=Files Encoding: LBL_CustomizeGeneral_RequiredProjects_JLabel=Required Projects: LBL_CustomizeGeneral_RequiredProjects_JCheckBox=Rebuild Required Projects @@ -124,4 +125,4 @@ #MainClassWarning CTL_MainClassWarning_Title=Warning - Running {0} Project LBL_MainClassNotFound={0} project doesn't have a main class set. -LBL_MainClassWarning_ChooseMainClass_OK=OK \ No newline at end of file +LBL_MainClassWarning_ChooseMainClass_OK=OK Index: java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerGeneral.form =================================================================== RCS file: /cvs/java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerGeneral.form,v retrieving revision 1.2 diff -u -r1.2 CustomizerGeneral.form --- java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerGeneral.form 16 Mar 2004 15:30:57 -0000 1.2 +++ java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerGeneral.form 30 Apr 2004 10:14:25 -0000 @@ -8,6 +8,9 @@ + + + @@ -61,6 +64,28 @@ + + + + + + + + + + + + + + + + + + + + + + Index: java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerGeneral.java =================================================================== RCS file: /cvs/java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerGeneral.java,v retrieving revision 1.3 diff -u -r1.3 CustomizerGeneral.java --- java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerGeneral.java 28 Apr 2004 15:02:25 -0000 1.3 +++ java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerGeneral.java 30 Apr 2004 10:14:25 -0000 @@ -65,6 +65,7 @@ public void initValues() { vps.register( jTextFieldDisplayName, J2SEProjectProperties.J2SE_PROJECT_NAME ); + vps.register( jTextFieldEncoding, J2SEProjectProperties.FILES_ENCODING ); vps.register( jCheckBoxReqPrj, J2SEProjectProperties.NO_DEPENDENCIES ); initPlatforms(vps); @@ -105,6 +106,8 @@ jLabelTarget = new javax.swing.JLabel(); jComboBoxTarget = new javax.swing.JComboBox(); jButton1 = new javax.swing.JButton(); + jLabelEncoding = new javax.swing.JLabel(); + jTextFieldEncoding = new javax.swing.JTextField(); jLabelReqPrj = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); jListSubprojects = new javax.swing.JList(); @@ -115,26 +118,26 @@ setBorder(new javax.swing.border.EtchedBorder()); jLabelProjectName.setText(org.openide.util.NbBundle.getMessage(CustomizerGeneral.class, "LBL_CustomizeGeneral_DisplayName_JLabel")); gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(12, 12, 12, 12); + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; add(jLabelProjectName, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(12, 0, 12, 12); + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; add(jTextFieldDisplayName, gridBagConstraints); jLabelTarget.setText(org.openide.util.NbBundle.getMessage(CustomizerGeneral.class, "LBL_CustomizeGeneral_Platform_JLabel")); gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 12, 12, 12); + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; add(jLabelTarget, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; add(jComboBoxTarget, gridBagConstraints); jButton1.setText(org.openide.util.NbBundle.getMessage(CustomizerGeneral.class, "LBL_CustomizeGeneral_Platform_JButton")); @@ -146,15 +149,29 @@ gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 6, 12, 12); + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; add(jButton1, gridBagConstraints); - jLabelReqPrj.setText(org.openide.util.NbBundle.getMessage(CustomizerGeneral.class, "LBL_CustomizeGeneral_RequiredProjects_JLabel")); + jLabelEncoding.setLabelFor(jTextFieldEncoding); + jLabelEncoding.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("LBL_CustomizeGeneral_Encoding_JLabel")); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.insets = new java.awt.Insets(0, 12, 12, 12); + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + add(jLabelEncoding, gridBagConstraints); + gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 12); gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + add(jTextFieldEncoding, gridBagConstraints); + + jLabelReqPrj.setText(org.openide.util.NbBundle.getMessage(CustomizerGeneral.class, "LBL_CustomizeGeneral_RequiredProjects_JLabel")); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.insets = new java.awt.Insets(0, 12, 2, 12); + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; add(jLabelReqPrj, gridBagConstraints); jScrollPane1.setViewportView(jListSubprojects); @@ -162,10 +179,10 @@ gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; + gridBagConstraints.insets = new java.awt.Insets(0, 12, 6, 12); gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 12, 6, 12); add(jScrollPane1, gridBagConstraints); jCheckBoxReqPrj.setText(org.openide.util.NbBundle.getMessage(CustomizerGeneral.class, "LBL_CustomizeGeneral_RequiredProjects_JCheckBox")); @@ -173,9 +190,9 @@ gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.insets = new java.awt.Insets(0, 12, 12, 12); gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 12, 12, 12); add(jCheckBoxReqPrj, gridBagConstraints); }//GEN-END:initComponents @@ -190,12 +207,14 @@ private javax.swing.JButton jButton1; private javax.swing.JCheckBox jCheckBoxReqPrj; private javax.swing.JComboBox jComboBoxTarget; + private javax.swing.JLabel jLabelEncoding; private javax.swing.JLabel jLabelProjectName; private javax.swing.JLabel jLabelReqPrj; private javax.swing.JLabel jLabelTarget; private javax.swing.JList jListSubprojects; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextField jTextFieldDisplayName; + private javax.swing.JTextField jTextFieldEncoding; // End of variables declaration//GEN-END:variables // Storing methods --------------------------------------------------------- Index: java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java =================================================================== RCS file: /cvs/java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java,v retrieving revision 1.9 diff -u -r1.9 J2SEProjectProperties.java --- java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java 30 Apr 2004 04:22:07 -0000 1.9 +++ java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java 30 Apr 2004 10:14:27 -0000 @@ -84,6 +84,7 @@ public static final String DIST_JAVADOC_DIR = "dist.javadoc.dir"; public static final String NO_DEPENDENCIES="no.dependencies"; public static final String DEBUG_TEST_CLASSPATH = "debug.test.classpath"; + public static final String FILES_ENCODING = "encoding"; public static final String JAVADOC_PRIVATE="javadoc.private"; @@ -143,6 +144,7 @@ new PropertyDescriptor( NO_DEPENDENCIES, PROJECT, INVERSE_BOOLEAN_PARSER ), new PropertyDescriptor( JAVA_PLATFORM, PROJECT, PLATFORM_PARSER ), new PropertyDescriptor( DEBUG_TEST_CLASSPATH, PROJECT, PATH_PARSER ), + new PropertyDescriptor( FILES_ENCODING, PROJECT, STRING_PARSER ), new PropertyDescriptor( JAVADOC_PRIVATE, PROJECT, BOOLEAN_PARSER ), new PropertyDescriptor( JAVADOC_NO_TREE, PROJECT, INVERSE_BOOLEAN_PARSER ), @@ -336,6 +338,12 @@ if (JAVA_PLATFORM.equals(pd.name)) { assert defaultPlatform != null; updateSourceLevel(defaultPlatform.booleanValue(), newValueEncoded, ep); + } + + // if encoding was removed then remove the property + if (FILES_ENCODING.equals(pd.name) && newValueEncoded.length() == 0) { + ep.remove(pd.name); + continue; } ep.setProperty( pd.name, newValueEncoded ); Index: projects/projectapi/src/META-INF/services/org.netbeans.spi.queries.FileEncodingQueryImplementation =================================================================== RCS file: projects/projectapi/src/META-INF/services/org.netbeans.spi.queries.FileEncodingQueryImplementation diff -N projects/projectapi/src/META-INF/services/org.netbeans.spi.queries.FileEncodingQueryImplementation --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ projects/projectapi/src/META-INF/services/org.netbeans.spi.queries.FileEncodingQueryImplementation 30 Apr 2004 10:14:31 -0000 @@ -0,0 +1 @@ +org.netbeans.modules.projectapi.FileEncodingQueryImpl Index: projects/projectapi/src/org/netbeans/modules/projectapi/FileEncodingQueryImpl.java =================================================================== RCS file: projects/projectapi/src/org/netbeans/modules/projectapi/FileEncodingQueryImpl.java diff -N projects/projectapi/src/org/netbeans/modules/projectapi/FileEncodingQueryImpl.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ projects/projectapi/src/org/netbeans/modules/projectapi/FileEncodingQueryImpl.java 30 Apr 2004 10:14:31 -0000 @@ -0,0 +1,43 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package org.netbeans.modules.projectapi; + +import java.net.URI; +import org.netbeans.api.project.FileOwnerQuery; +import org.netbeans.api.project.Project; +import org.netbeans.spi.queries.FileEncodingQueryImplementation; + +/** + * Finds project owning given file, FileEncodingQueryImplementation impl in its + * lookup and delegates question to it. + * @author David Konecny + */ +public class FileEncodingQueryImpl implements FileEncodingQueryImplementation { + + /** Default constructor for lookup. */ + public FileEncodingQueryImpl() {} + + public String getFileEncoding(org.openide.filesystems.FileObject file) { + Project project = FileOwnerQuery.getOwner(file); + if (project != null) { + FileEncodingQueryImplementation feq = + (FileEncodingQueryImplementation)project.getLookup().lookup( + FileEncodingQueryImplementation.class); + if (feq != null) { + return feq.getFileEncoding(file); + } + } + return null; + } + +} Index: projects/queries/src/org/netbeans/api/queries/FileEncodingQuery.java =================================================================== RCS file: projects/queries/src/org/netbeans/api/queries/FileEncodingQuery.java diff -N projects/queries/src/org/netbeans/api/queries/FileEncodingQuery.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ projects/queries/src/org/netbeans/api/queries/FileEncodingQuery.java 30 Apr 2004 10:14:32 -0000 @@ -0,0 +1,55 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package org.netbeans.api.queries; + +import java.util.Iterator; +import org.netbeans.spi.queries.FileEncodingQueryImplementation; +import org.openide.filesystems.FileObject; +import org.openide.util.Lookup; + +/** + * Query to find encoding of a file. + * @see org.netbeans.api.java.queries.FileEncodingQueryImplementation + * @author David Konecny + * @since XXX + */ +public class FileEncodingQuery { + + private static final Lookup.Result/**/ implementations = + Lookup.getDefault().lookup(new Lookup.Template(FileEncodingQueryImplementation.class)); + + private FileEncodingQuery() { + } + + /** + * Returns encoding of the given file if it is known. + * @param file FileObject in question + * @return encoding of the file or null if nothing is known about + * file's encoding + */ + public static String getFileEncoding(FileObject file) { + if (file.isFolder()) { + throw new IllegalArgumentException("Not a file: " + file); // NOI18N + } + Iterator it = implementations.allInstances().iterator(); + while (it.hasNext()) { + FileEncodingQueryImplementation sqi = (FileEncodingQueryImplementation)it.next(); + String s = sqi.getFileEncoding(file); + if (s != null) { + return s; + } + } + return null; + } + +} Index: projects/queries/src/org/netbeans/spi/queries/FileEncodingQueryImplementation.java =================================================================== RCS file: projects/queries/src/org/netbeans/spi/queries/FileEncodingQueryImplementation.java diff -N projects/queries/src/org/netbeans/spi/queries/FileEncodingQueryImplementation.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ projects/queries/src/org/netbeans/spi/queries/FileEncodingQueryImplementation.java 30 Apr 2004 10:14:32 -0000 @@ -0,0 +1,43 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package org.netbeans.spi.queries; + +import org.openide.filesystems.FileObject; + +/** + * Permits providers to return encoding of the file. + *

+ * A default implementation is registered by the + * org.netbeans.modules.project.ant module which looks up the + * project corresponding to the file (if any) and checks whether that + * project has an implementation of this interface in its lookup. If so, it + * delegates to that implementation. Therefore it is not generally necessary + * for a project type provider to register its own global implementation of + * this query, if it depends on the ant project module and uses this style. + *

+ * @see org.netbeans.api.queries.FileEncodingQuery + * @see org.netbeans.api.queries.FileOwnerQuery + * @see org.netbeans.api.project.Project#getLookup + * @author David Konecny + * @since XXX + */ +public interface FileEncodingQueryImplementation { + + /** + * Returns file encoding. + * @param file FileObject in question + * @return file encoding or null if nothing is known about file's encoding + */ + public String getFileEncoding(FileObject file); + +}