diff --git a/nbbuild/antsrc/org/netbeans/nbbuild/CheckLicense.java b/nbbuild/antsrc/org/netbeans/nbbuild/CheckLicense.java
index 7120bdbabe31..9b7b77b7bb57 100644
--- a/nbbuild/antsrc/org/netbeans/nbbuild/CheckLicense.java
+++ b/nbbuild/antsrc/org/netbeans/nbbuild/CheckLicense.java
@@ -102,11 +102,9 @@ public Convert createConvert() {
while ((line = br.readLine ()) != null) {
if (line.indexOf (fragment) != -1) {
// Found it.
- if (fail != null && "whenpresent".equals(fail.getValue())) {
- if (failMsg != null) {
- log(failMsg, Project.MSG_ERR);
- }
+ if (fail != null && "whenpresent".equals(fail.getValue())) {
failMsg = "License found in " + f;
+ log(failMsg, Project.MSG_ERR);
}
break;
}
diff --git a/nbbuild/build.properties b/nbbuild/build.properties
index 0b7917e6e355..2311f404f16c 100644
--- a/nbbuild/build.properties
+++ b/nbbuild/build.properties
@@ -21,6 +21,8 @@ test.dist.dir=build/testdist
test.user.dir=testuserdir
nb.run.validation=true
build.compiler.debug=on
+
+bootstrap.jdk.release=11
# Options to pass to NetBeans when starting it with "ant tryme":
tryme.arg.hack=-J-Dnetbeans.full.hack=true
@@ -55,8 +57,10 @@ stop.when.clean.error=true
test.unit.cp=\
../platform/libs.junit4/external/junit-4.13.2.jar:\
+ ../platform/libs.junit4/external/hamcrest-core-1.3.jar:\
netbeans/harness/modules/org-netbeans-modules-nbjunit.jar:\
netbeans/harness/modules/org-netbeans-insane.jar:\
+ ${ant.home}/lib/ant-testutil.jar:\
${ant.home}/lib/ant-junit.jar:\
${ant.home}/lib/ant-junit4.jar:\
${ant.home}/lib/ant-launcher.jar:\
diff --git a/nbbuild/build.xml b/nbbuild/build.xml
index 7f4099c77b3b..d9917bbd3317 100644
--- a/nbbuild/build.xml
+++ b/nbbuild/build.xml
@@ -59,7 +59,7 @@
-
+
@@ -99,7 +99,7 @@
-
+
@@ -1366,9 +1366,9 @@ It is possible to use -Ddebug.port=3234 -Ddebug.pause=y to start the system in d
-
+
-
+
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/ArchQuestionsTest.java b/nbbuild/test/unit/src/org/netbeans/nbbuild/ArchQuestionsTest.java
index 8886f578ce3e..5a93fe91799e 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/ArchQuestionsTest.java
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/ArchQuestionsTest.java
@@ -18,7 +18,7 @@
*/
package org.netbeans.nbbuild;
-
+import org.apache.tools.ant.BuildFileRule;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
@@ -26,6 +26,7 @@
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+import org.junit.Rule;
import org.w3c.dom.Document;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
@@ -38,18 +39,28 @@
public class ArchQuestionsTest extends TestBase implements EntityResolver {
/** debug messages to show if necessary */
private List msg = new ArrayList<>();
-
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ System.clearProperty("arch.generate");
+ System.clearProperty("arch.private.disable.validation.for.test.purposes");
+ System.clearProperty("arch.org.openide.util.name");
+ System.clearProperty("arch.org.openide.util.category");
+ }
public ArchQuestionsTest (String name) {
super (name);
}
-
+
public void testGeneratePreferencesArch() throws Exception {
java.io.File answers = extractResource("arch-preferences.xml");
java.io.File output = extractString("");
output.delete();
-
-
-
+
+
+
java.io.File f = extractString(
"" +
"" +
@@ -58,12 +69,13 @@ public void testGeneratePreferencesArch() throws Exception {
" " +
"" +
""
-
+
);
- execute(f, new String[] { });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue("File is generated", output.exists());
-
+
String content = readFile(output);
if (content.indexOf("resources-preferences") == -1) {
fail("resources-preferences shall be in output:\n" + content);
@@ -73,7 +85,7 @@ public void testGeneratePreferencesArch() throws Exception {
}
}
-
+
public void testGenerateArchFileWhenEmpty () throws Exception {
java.io.File answers = extractString ("");
answers.delete ();
@@ -90,12 +102,14 @@ public void testGenerateArchFileWhenEmpty () throws Exception {
""
);
- execute (f, new String[] { });
+
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertTrue ("File is generated", answers.exists ());
-
+
String content = readFile(answers);
-
+
if (content.indexOf("module=") >= 0) {
fail("No mention of a module should be there anymore:\n" + content);
}
@@ -117,10 +131,12 @@ public void testGenerateArchFileWhenEmptyWithDefaultAnswerForNbDepsQuestion() th
""
);
- execute (f, new String[] { });
+
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertTrue ("File is generated", answers.exists ());
-
+
String res = readFile(answers);
DocumentBuilderFactory fack = DocumentBuilderFactory.newInstance();
fack.setValidating(false);
@@ -140,7 +156,7 @@ public void testGenerateArchFileWhenEmptyWithDefaultAnswerForNbDepsQuestion() th
while (n != null) {
n = n.getParentNode();
assertNotNull ("No parent node answer found: " + res, n);
-
+
if (n.getNodeName().equals ("answer")) {
String id = n.getAttributes().getNamedItem("id").getNodeValue();
if (id.equals ("dep-nb")) {
@@ -151,10 +167,10 @@ public void testGenerateArchFileWhenEmptyWithDefaultAnswerForNbDepsQuestion() th
}
}
}
-
+
fail ("dep-nb question should have a defaultanswer: " + res);
}
-
+
public void testDoNotCorruptTheFileWhenItExists() throws Exception {
java.io.File answers = extractString (
"\n" +
@@ -174,7 +190,7 @@ public void testDoNotCorruptTheFileWhenItExists() throws Exception {
">\n" +
"\n" +
// "&api-questions;\n" +
- // replaced by part of api-questions entity
+ // replaced by part of api-questions entity
"\n" +
"\n" +
"\n" +
@@ -200,7 +216,7 @@ public void testDoNotCorruptTheFileWhenItExists() throws Exception {
"\n" +
"\n" +
" \n" +
-// end of Arch-api-questionx.xmls
+// end of Arch-api-questionx.xmls
"\n" +
"\n" +
"\n" +
@@ -211,9 +227,9 @@ public void testDoNotCorruptTheFileWhenItExists() throws Exception {
"\n" +
" \n"
);
-
+
java.io.File output = extractString("");
-
+
java.io.File f = extractString (
"" +
"" +
@@ -225,15 +241,14 @@ public void testDoNotCorruptTheFileWhenItExists() throws Exception {
""
);
- execute (f, new String[] {
- "-Darch.generate=true",
- "-Darch.private.disable.validation.for.test.purposes=true",
-
- });
+ System.setProperty("arch.generate", "true");
+ System.setProperty("arch.private.disable.validation.for.test.purposes", "true");
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertTrue ("Answers still exists", answers.exists ());
assertTrue ("Output file generated", output.exists ());
-
+
String s1 = readFile(answers);
if (s1.indexOf("answer id=\"arch-overall\"") == -1) {
fail ("There should be a answer template for arch-overall in answers: " + s1);
@@ -250,8 +265,8 @@ public void testDoNotCorruptTheFileWhenItExists() throws Exception {
}
}
-
-
+
+
public void testIncludeAPIChangesDocumentIntoSetOfAnswersIfSpecified() throws Exception {
java.io.File answers = extractString (
"\n" +
@@ -271,7 +286,7 @@ public void testIncludeAPIChangesDocumentIntoSetOfAnswersIfSpecified() throws Ex
">\n" +
"\n" +
// "&api-questions;\n" +
- // replaced by part of api-questions entity
+ // replaced by part of api-questions entity
"\n" +
"\n" +
"\n" +
@@ -297,7 +312,7 @@ public void testIncludeAPIChangesDocumentIntoSetOfAnswersIfSpecified() throws Ex
"\n" +
"\n" +
" \n" +
-// end of Arch-api-questionx.xmls
+// end of Arch-api-questionx.xmls
"\n" +
"\n" +
"\n" +
@@ -308,7 +323,7 @@ public void testIncludeAPIChangesDocumentIntoSetOfAnswersIfSpecified() throws Ex
"\n" +
" \n"
);
-
+
java.io.File apichanges = extractString(
"\n" +
"\n";
String script = createScript();
-
-
+
+
File fileScript = extractString(script);
File fileTxt = extractString(txt);
-
- execute (fileScript, new String[] {
- "-Ddir=" + fileTxt.getParent(),
- "-Dinclude=" + fileTxt.getName(),
- });
-
- if (getStdOut().indexOf("Original Code") != - 1) {
- fail("Original Code shall not be there: " + getStdOut());
+
+ System.setProperty("dir", fileTxt.getParentFile().getAbsolutePath() );
+ System.setProperty("include", fileTxt.getName() );
+ buildRule.configureProject(fileScript.getAbsolutePath());
+ buildRule.executeTarget("all");
+ if (buildRule.getFullLog().indexOf("Original Code") != - 1) {
+ fail("Original Code shall not be there: " + buildRule.getFullLog());
}
String out = readFile(fileTxt);
-
+
String[] arr = out.split("\n");
for (int i = 0; i < arr.length; i++) {
if (arr[i].endsWith(" ")) {
@@ -434,7 +445,7 @@ public void testWrongLineBeginningsWhenNoPrefix() throws Exception {
if (arr[i].charAt(0) != ' ') {
continue;
}
-
+
fail("This line seems to start with space:\n" + arr[i] + "\nwhich is wrong in whole output:\n" + out);
}
}
@@ -447,9 +458,9 @@ private static String createScript() {
"" +
" \n" +
" \n" +
-" " +
+" " +
" \n" +
-"\n" +
+"\n" +
" \n";
return script;
}
-
+
public void testReplacesTextSeparatedByNewLine() throws Exception {
if (isWindows()) {
return;
@@ -506,15 +517,16 @@ public void testReplacesTextSeparatedByNewLine() throws Exception {
File java = new File(tmp.getParentFile(), "MyTest.html");
tmp.renameTo(java);
assertTrue("File exists", java.exists());
-
- execute (f, new String[] {
- "-Ddir=" + java.getParent(),
- "-Dinclude=" + java.getName(),
- });
-
- if (getStdOut().indexOf("Code") != - 1) {
- fail("Original Code shall not be there: " + getStdOut());
+
+ System.setProperty("dir", java.getParentFile().getAbsolutePath() );
+ System.setProperty("include", java.getName() );
+
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
+ if (buildRule.getFullLog().indexOf("Code") != - 1) {
+ fail("Original Code shall not be there: " + buildRule.getFullLog());
}
String out = readFile(java);
@@ -525,7 +537,7 @@ public void testReplacesTextSeparatedByNewLine() throws Exception {
if (out.indexOf("Software", first + 25) == - 1) {
fail("Original Software shall be there: " + out);
}
-
+
String[] lines = out.split("\n");
for (int i = 0; i < lines.length; i++) {
if (lines[i].length() > 80) {
@@ -535,10 +547,10 @@ public void testReplacesTextSeparatedByNewLine() throws Exception {
fail("Ends with space: '" + lines[i] + "' in:\n" + out);
}
}
- }
-
-
-
+ }
+
+
+
public void testWorksOnEmptyFile() throws Exception {
java.io.File f = extractResource("CheckLicenseAnt.xml");
@@ -546,19 +558,17 @@ public void testWorksOnEmptyFile() throws Exception {
File html = new File(tmp.getParentFile(), "MyTest.html");
tmp.renameTo(html);
assertTrue("File exists", html.exists());
-
-
- execute (f, new String[] {
- "-Ddir=" + html.getParent(),
- "-Dinclude=" + html.getName(),
- });
-
- if (getStdOut().indexOf(html.getPath()) != - 1) {
- fail("file name shall not be there: " + getStdOut());
- }
-
- }
-
+
+ System.setProperty("dir", html.getParentFile().getAbsolutePath() );
+ System.setProperty("include", html.getName() );
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+ if (buildRule.getLog().indexOf(html.getPath()) != - 1) {
+ fail("file name shall not be there: " + buildRule.getLog());
+ }
+
+ }
+
public void testReplacePropertiesLicense() throws Exception {
if (isWindows()) {
return;
@@ -569,42 +579,42 @@ public void testReplacePropertiesLicense() throws Exception {
File html = new File(tmp.getParentFile(), "MyTest.html");
tmp.renameTo(html);
assertTrue("File exists", html.exists());
-
-
- execute (f, new String[] {
- "-verbose",
- "-Ddir=" + html.getParent(),
- "-Dinclude=" + html.getName(),
- });
-
- if (getStdOut().indexOf(html.getPath()) == - 1) {
- fail("file name shall be there: " + getStdOut());
- }
-
-
+
+
+ System.setProperty("dir", html.getParentFile().getAbsolutePath() );
+ System.setProperty("include", html.getName() );
+
+ buildRule.configureProject(f.getAbsolutePath(),Project.MSG_VERBOSE);
+ buildRule.executeTarget("all");
+
+ if (buildRule.getFullLog().indexOf(html.getPath()) == - 1) {
+ fail("file name shall be there: " + buildRule.getFullLog());
+ }
+
+
assertTrue("Still exists", html.exists());
-
-
+
+
String content = readFile(html);
-
+
if (!content.startsWith("#")) {
fail("Shall start with #:\n" + content);
}
-
+
{
Matcher m = Pattern.compile(" *\\# *Ahoj *\\# *Jardo").matcher(content.replace('\n', ' '));
if (!m.find()) {
fail("Replacement shall be there together with prefix:\n" + content);
}
}
-
+
{
Matcher m = Pattern.compile("^ *\\#New. *\\#Warning", Pattern.MULTILINE | Pattern.DOTALL).matcher(content);
if (!m.find()) {
fail("warning shall be there:\n" + content);
}
}
-
+
{
String[] lines = content.split("\n");
if (lines.length < 5) {
@@ -622,13 +632,13 @@ public void testReplacePropertiesLicense() throws Exception {
}
}
}
- }
+ }
private static boolean isWindows() {
String name = System.getProperty("os.name");
return name != null && name.toLowerCase().indexOf("windows") >= 0;
}
-
+
public void testReplaceXMLLicense() throws Exception {
java.io.File f = extractResource("CheckLicenseAnt.xml");
@@ -636,45 +646,43 @@ public void testReplaceXMLLicense() throws Exception {
File xml = new File(tmp.getParentFile(), "MyTest.xml");
tmp.renameTo(xml);
assertTrue("File exists", xml.exists());
-
-
- execute (f, new String[] {
- "-verbose",
- "-Ddir=" + xml.getParent(),
- "-Dinclude=" + xml.getName(),
- });
-
- if (getStdOut().indexOf(xml.getPath()) == - 1) {
- fail("file name shall be there: " + getStdOut());
- }
-
-
+
+
+ System.setProperty("dir", xml.getParentFile().getAbsolutePath() );
+ System.setProperty("include", xml.getName() );
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+ if (buildRule.getFullLog().indexOf(xml.getPath()) == - 1) {
+ fail("file name shall be there: " + buildRule.getFullLog());
+ }
+
+
assertTrue("Still exists", xml.exists());
-
-
+
+
String content = readFile(xml);
-
+
if (!content.startsWith("<")) {
fail("Shall start with <:\n" + content);
}
-
+
{
Matcher m = Pattern.compile(" *Ahoj *Jardo").matcher(content.replace('\n', ' '));
if (!m.find()) {
fail("Replacement shall be there together with prefix:\n" + content);
}
}
-
+
{
Matcher m = Pattern.compile("^ *New. *Warning", Pattern.MULTILINE | Pattern.DOTALL).matcher(content);
if (!m.find()) {
fail("warning shall be there:\n" + content);
}
}
- }
+ }
public void testProblemsWithTermEmulator() throws Exception {
- String txt =
+ String txt =
"/* \n" +
" * Sun Public License Notice\n" +
" *\n" +
@@ -691,18 +699,17 @@ public void testProblemsWithTermEmulator() throws Exception {
" * Contributor(s): Ivan Soleimanipour.\n" +
" */\n";
String script = createScript();
-
-
+
+
File fileScript = extractString(script);
File fileTxt = extractString(txt);
-
- execute (fileScript, new String[] {
- "-Ddir=" + fileTxt.getParent(),
- "-Dinclude=" + fileTxt.getName(),
- });
-
- if (getStdOut().indexOf("Original Code") != - 1) {
- fail("Original Code shall not be there: " + getStdOut());
+
+ System.setProperty("dir", fileTxt.getParentFile().getAbsolutePath() );
+ System.setProperty("include", fileTxt.getName() );
+ buildRule.configureProject(fileScript.getAbsolutePath());
+ buildRule.executeTarget("all");
+ if (buildRule.getFullLog().indexOf("Original Code") != - 1) {
+ fail("Original Code shall not be there: " + buildRule.getFullLog());
}
String out = readFile(fileTxt);
@@ -713,7 +720,7 @@ public void testProblemsWithTermEmulator() throws Exception {
}
}
-
+
public void testDoubleHtmlComments() throws Exception {
java.io.File f = extractString(createScript());
@@ -734,20 +741,19 @@ public void testDoubleHtmlComments() throws Exception {
File file = new File(tmp.getParentFile(), "MyTest.html");
tmp.renameTo(file);
assertTrue("File exists", file.exists());
-
- execute (f, new String[] {
- "-Ddir=" + file.getParent(),
- "-Dinclude=" + file.getName(),
- });
-
+
+ System.setProperty("dir", file.getParentFile().getAbsolutePath() );
+ System.setProperty("include", file.getName() );
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
String out = readFile(file);
int first = out.indexOf("Sun Public");
if (first != - 1) {
fail("Sun Public shall not be there:\n" + out);
}
- }
-
+ }
+
public void testDoNotReplaceSpacesBeyondTheLicense() throws Exception {
StringBuffer sb = new StringBuffer();
sb.append('A');
@@ -755,7 +761,7 @@ public void testDoNotReplaceSpacesBeyondTheLicense() throws Exception {
sb.append(' ');
}
sb.append('B');
-
+
java.io.File license = extractString(
"\n" +
"\n" +
@@ -764,22 +770,19 @@ public void testDoNotReplaceSpacesBeyondTheLicense() throws Exception {
sb
);
String script = createScript();
-
-
- execute (
- extractString(script),
- new String[] {
- "-Ddir=" + license.getParent(),
- "-Dinclude=" + license.getName(),
- });
-
+
+ java.io.File scriptf = extractString(script);
+ System.setProperty("dir", license.getParentFile().getAbsolutePath() );
+ System.setProperty("include", license.getName() );
+ buildRule.configureProject(scriptf.getAbsolutePath());
+ buildRule.executeTarget("all");
String out = readFile(license);
if (out.indexOf("Sun Public") >= 0) {
fail(out);
}
-
+
Matcher m = Pattern.compile("A( *)B").matcher(out);
if (!m.find()) {
fail("There should be long line:\n" + out);
@@ -787,7 +790,7 @@ public void testDoNotReplaceSpacesBeyondTheLicense() throws Exception {
if (m.group(1).length() != 10000) {
fail("There should be 10000 spaces, but is only: " + m.group(1).length() + "\n" + out);
}
- }
+ }
}
-
+
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/CheckLinksTest.java b/nbbuild/test/unit/src/org/netbeans/nbbuild/CheckLinksTest.java
index 5b32498a1d89..1eec9cceb985 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/CheckLinksTest.java
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/CheckLinksTest.java
@@ -20,12 +20,19 @@
package org.netbeans.nbbuild;
import java.io.File;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Rule;
/** Check the behaviour of CheckLinks.
*
* @author Jaroslav Tulach
*/
public class CheckLinksTest extends TestBase {
+
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
+
public CheckLinksTest (String name) {
super (name);
}
@@ -49,7 +56,8 @@ public void testByDefaultAllURLsAreAllowed () throws Exception {
""
);
// success
- execute (f, new String[] { });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
}
@@ -73,9 +81,10 @@ public void testForbiddenExternalURLsAreCorrectlyReported () throws Exception {
""
);
try {
- execute (f, new String[] { });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
fail ("This should fail as the URL is forbidden");
- } catch (ExecutionError ex) {
+ } catch (BuildException ex) {
// ok, this should fail on exit code
}
}
@@ -95,9 +104,10 @@ public void testForbiddenURLsInLinkElements() throws Exception {
""
);
try {
- execute(f, new String[] {});
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
fail();
- } catch (ExecutionError ex) {}
+ } catch (BuildException ex) {}
}
public void testAnyURLCanBeForbidden () throws Exception {
@@ -120,9 +130,10 @@ public void testAnyURLCanBeForbidden () throws Exception {
""
);
try {
- execute (f, new String[] { });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
fail ("This should fail as the URL is forbidden");
- } catch (ExecutionError ex) {
+ } catch (BuildException ex) {
// ok, this should fail on exit code
}
}
@@ -148,7 +159,8 @@ public void testIfAcceptedFirstThenItDoesNotMatterThatItIsForbiddenLater () thro
""
);
// passes as .*sex.* is acceptable
- execute (f, new String[] { });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
}
@@ -174,7 +186,8 @@ public void testSkipCommentedOutLinks () throws Exception {
""
);
// passes as the forbidden URL is commented out
- execute (f, new String[] { });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
}
@@ -198,7 +211,8 @@ public void testDocFilesRelativeLinks () throws Exception {
""
);
// success
- execute (f, new String[] { });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
}
@@ -222,9 +236,10 @@ public void testDocFilesInvalidLinks () throws Exception {
);
// failure
try {
- execute (f, new String[] { });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
fail ("This should fail as the link is broken");
- } catch (ExecutionError ex) {
+ } catch (BuildException ex) {
// ok, this should fail on exit code
}
}
@@ -250,7 +265,8 @@ public void testQueryComponent() throws Exception {
"" +
""
);
- execute(f, new String[] {});
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
}
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/CreateModuleXMLTest.java b/nbbuild/test/unit/src/org/netbeans/nbbuild/CreateModuleXMLTest.java
index 28a9513ada1f..637c8b55fdc7 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/CreateModuleXMLTest.java
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/CreateModuleXMLTest.java
@@ -24,6 +24,9 @@
import java.util.jar.Manifest;
import java.io.File;
import java.io.IOException;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Rule;
/** Check behaviour of ModuleSelector.
@@ -31,7 +34,9 @@
* @author Jaroslav Tulach
*/
public class CreateModuleXMLTest extends TestBase {
-
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
+
public CreateModuleXMLTest(String testName) {
super(testName);
}
@@ -40,15 +45,15 @@ public void testIncludesAllModulesByDefault() throws Exception {
Manifest m = createManifest ();
m.getMainAttributes().putValue("OpenIDE-Module", "org.my.module");
File aModule = generateJar(new String[0], m);
-
+
File output = new File(getWorkDir(), "output");
-
+
java.io.File f = extractString (
"" +
"" +
" " +
"" +
- " " +
+ " " +
" " +
" " +
" " +
@@ -57,15 +62,15 @@ public void testIncludesAllModulesByDefault() throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertTrue ("Output exists", output.exists ());
assertTrue ("Output directory created", output.isDirectory());
-
+
String[] files = output.list();
assertEquals("It one file", 1, files.length);
assertEquals("Its name reflects the code name of the module", "org-my-module.xml_hidden", files[0]);
-
+
}
public void testGeneratesDataForDisabledModule() throws Exception {
@@ -89,8 +94,8 @@ public void testGeneratesDataForDisabledModule() throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertTrue ("Output exists", output.exists ());
assertTrue ("Output directory created", output.isDirectory());
@@ -99,7 +104,7 @@ public void testGeneratesDataForDisabledModule() throws Exception {
assertEquals("Its name reflects the code name of the module", "org-my-module.xml", files[0]);
}
-
+
public void testStartLevelFailsForNormalModules() throws Exception {
Manifest m = createManifest ();
m.getMainAttributes().putValue("OpenIDE-Module", "org.my.module");
@@ -122,8 +127,9 @@ public void testStartLevelFailsForNormalModules() throws Exception {
""
);
try {
- execute(f, new String[] { "-verbose" });
- } catch (ExecutionError ex) {
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+ } catch (BuildException ex) {
// OK
return;
}
@@ -151,7 +157,9 @@ public void testStartLevelIsIgnoredForNormalModulesWhenRequested() throws Except
"" +
""
);
- execute (f, new String[] { "-verbose" });
+
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertTrue ("Output exists", output.exists ());
assertTrue ("Output directory created", output.isDirectory());
@@ -159,11 +167,11 @@ public void testStartLevelIsIgnoredForNormalModulesWhenRequested() throws Except
File[] files = output.listFiles();
assertEquals("It one file", 1, files.length);
assertEquals("Its name reflects the code name of the module", "org-my-module.xml", files[0].getName());
-
+
String content = readFile(files[0]);
assertFalse("startlevel tag is not there: " + content, content.contains("\"startlevel\""));
}
-
+
public void testStartLevelOKForBundles() throws Exception {
Manifest m = createManifest ();
m.getMainAttributes().putValue("Bundle-SymbolicName", "org.my.module");
@@ -185,15 +193,15 @@ public void testStartLevelOKForBundles() throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertTrue ("Output exists", output.exists ());
assertTrue ("Output directory created", output.isDirectory());
File[] files = output.listFiles();
assertEquals("It one file", 1, files.length);
assertEquals("Its name reflects the code name of the module", "org-my-module.xml", files[0].getName());
-
+
String content = readFile(files[0]);
assertTrue("startlevel tag expected: " + content, content.contains("\"startlevel\""));
@@ -219,8 +227,8 @@ public void testEmptyStartLevelIsOKForNormalModules() throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertTrue ("Output exists", output.exists ());
assertTrue ("Output directory created", output.isDirectory());
@@ -253,7 +261,10 @@ public void testGenerateUpdateTrackingMode() throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
+
+
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertTrue ("Output exists", output.exists ());
assertTrue ("Output directory created", output.isDirectory());
@@ -287,12 +298,12 @@ public void testGenerateUpdateTrackingMode() throws Exception {
}
}
}
-
-
+
+
private File createNewJarFile() throws IOException {
File dir = new File(this.getWorkDir(), "modules");
dir.mkdirs();
-
+
int i = 0;
for (;;) {
File f = new File (dir, i++ + ".jar");
@@ -301,25 +312,25 @@ private File createNewJarFile() throws IOException {
}
}
}
-
+
protected final File generateJar (String[] content, Manifest manifest) throws IOException {
File f = createNewJarFile ();
-
+
JarOutputStream os;
if (manifest != null) {
os = new JarOutputStream (new FileOutputStream (f), manifest);
} else {
os = new JarOutputStream (new FileOutputStream (f));
}
-
+
for (int i = 0; i < content.length; i++) {
os.putNextEntry(new JarEntry (content[i]));
os.closeEntry();
}
os.closeEntry ();
os.close();
-
+
return f;
}
-
+
}
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/FixDependenciesTest.java b/nbbuild/test/unit/src/org/netbeans/nbbuild/FixDependenciesTest.java
index 7c6dfbd7153a..38f53af853b2 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/FixDependenciesTest.java
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/FixDependenciesTest.java
@@ -22,6 +22,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Rule;
/** Behaviour of fixing module dependencies. Knows how to replace old
@@ -30,6 +32,9 @@
* @author Jaroslav Tulach
*/
public class FixDependenciesTest extends TestBase {
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
+
public FixDependenciesTest (String name) {
super (name);
}
@@ -56,7 +61,8 @@ public void testWrongIndentation() throws Exception {
);
String input = readFile (xml);
- execute (f, new String[] { });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
String result = readFile (xml);
if (result.indexOf ("org.openide.util") == -1) {
@@ -119,7 +125,9 @@ public void testCanFixXmlWsdlModel() throws Exception {
);
- execute (f, new String[] { });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
String result = readFile (xml);
if (result.indexOf ("org.openide.util") == -1) {
@@ -152,7 +160,8 @@ public void testCanParseCoreKit () throws Exception {
);
String before = readFile(xml);
- execute (f, new String[] { });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
String after = readFile(xml);
assertEquals("No change", before, after);
@@ -180,7 +189,9 @@ public void testCanParseOpenideUtil () throws Exception {
);
String before = readFile(xml);
- execute (f, new String[] { });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
String after = readFile(xml);
assertEquals("No change", before, after);
@@ -220,7 +231,8 @@ public void testNoModuleDependenciesDoesNotCrash() throws Exception {
);
String before = readFile(xml);
- execute (f, new String[] { });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
String after = readFile(xml);
assertEquals("No change", before, after);
@@ -260,7 +272,8 @@ public void testReplaceOpenideDepWithSmallerOnes () throws Exception {
""
);
- execute (f, new String[] { });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
String result = readFile (xml);
@@ -311,8 +324,8 @@ public void testReplaceOpenideUtilWithUtilAndLookup () throws Exception {
""
);
- execute (f, new String[] { });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
String result = readFile (xml);
if (result.indexOf ("org.openide.util") == -1) {
@@ -372,8 +385,8 @@ private void doDontReplaceNewerVersionOfItself(String version) throws Exception
""
);
- execute (f, new String[] { });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
String result = readFile (xml);
if (result.indexOf ("org.openide.util") == -1) {
@@ -464,8 +477,9 @@ public void testVerificationOfRemovedDependencies () throws Exception {
""
);
- execute (f, new String[] { "-Dbuildscript=" + f.getPath () });
-
+ System.setProperty("buildscript", f.getAbsolutePath());
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
String result = readFile (xml);
if (result.indexOf ("org.openide.keep") == -1) {
@@ -570,7 +584,9 @@ public void testBrokenCoreSettingsReplacement () throws Exception {
assertNotNull ("Originally can be parsed", doc);
- execute (f, new String[] { "-Dbuildscript=" + f.getPath () });
+ System.setProperty("buildscript", f.getAbsolutePath());
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
doc = javax.xml.parsers.DocumentBuilderFactory.newInstance ().newDocumentBuilder ().parse (xml);
@@ -644,7 +660,9 @@ public void testPropertiesAreNotInfluencedByPreviousExecution () throws Exceptio
""
);
- execute (f, new String[] { "-Dbuildscript=" + f.getPath () });
+ System.setProperty("buildscript", f.getAbsolutePath());
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
String result = readFile (xml);
@@ -728,8 +746,9 @@ public void testOnlyCompileTimeDependenciesCanBeRemoved () throws Exception {
""
);
- execute (f, new String[] { "-Dbuildscript=" + f.getPath () });
-
+ System.setProperty("buildscript", f.getAbsolutePath());
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
String result = readFile (xml);
if (result.indexOf ("org.openide.keep") == -1) {
@@ -785,8 +804,9 @@ public void testRuntimeDepOnOpenideIsSpecial () throws Exception {
""
);
- execute (f, new String[] { "-Dbuildscript=" + f.getPath () });
-
+ System.setProperty("buildscript", f.getAbsolutePath());
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
String result = readFile (xml);
if (result.indexOf ("org.openide") > -1) {
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/FixTestDependenciesProject2.xml b/nbbuild/test/unit/src/org/netbeans/nbbuild/FixTestDependenciesProject2.xml
index a10cb176fcb7..613e30f25ab2 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/FixTestDependenciesProject2.xml
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/FixTestDependenciesProject2.xml
@@ -217,14 +217,6 @@
6.5
-
- org.openide.options
-
-
-
- 6.2
-
-
org.openide.src
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/FixTestDependenciesProjectPass.xml b/nbbuild/test/unit/src/org/netbeans/nbbuild/FixTestDependenciesProjectPass.xml
index 31488c2d46bf..146d2087450f 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/FixTestDependenciesProjectPass.xml
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/FixTestDependenciesProjectPass.xml
@@ -217,14 +217,6 @@
6.5
-
- org.openide.options
-
-
-
- 6.2
-
-
org.openide.src
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/InsertModuleAllTargetsTest.java b/nbbuild/test/unit/src/org/netbeans/nbbuild/InsertModuleAllTargetsTest.java
index 259486a1756f..550e7894edc1 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/InsertModuleAllTargetsTest.java
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/InsertModuleAllTargetsTest.java
@@ -102,14 +102,14 @@ public void testInstallAllTargetWithClusters() {
insert.setProject(p);
insert.execute();
-
+
Object obj = p.getTargets().get("all-java.source.queries");
assertNotNull("Target found", obj);
Target t = (Target)obj;
Set s = depsToNames(t.getDependencies());
- assertEquals("Five dependencies: " + s, 5, s.size());
- assertEquals(new HashSet<>(Arrays.asList("init", "all-openide.dialogs", "all-openide.util", "all-openide.util.lookup", "all-api.annotations.common")), s);
+ assertEquals("Five dependencies: " + s, 2, s.size());
+ assertEquals(new HashSet<>(Arrays.asList("init", "all-cluster-nb.cluster.java")), s);
int callTargets = 0;
for (Task task : t.getTasks()) {
@@ -148,10 +148,10 @@ public void testInstallAllTargetWithoutClusters() {
assertEquals("No call targes", 0, callTargets);
}
- private Set depsToNames(Enumeration en) {
+ private Set depsToNames(Enumeration en) {
Set set = new HashSet<>();
while (en.hasMoreElements()) {
- String dep = en.nextElement().toString();
+ String dep = en.nextElement();
set.add(dep);
}
return set;
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/IsLockedTest.java b/nbbuild/test/unit/src/org/netbeans/nbbuild/IsLockedTest.java
index 489711f9eb82..532975aa18fd 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/IsLockedTest.java
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/IsLockedTest.java
@@ -38,7 +38,7 @@ protected void setUp() throws Exception {
condition = new IsLocked();
condition.setFile(file);
}
-
+
public void testCanLock() {
assertFalse("Is not locked", condition.eval());
}
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/JarWithModuleAttributesTest.java b/nbbuild/test/unit/src/org/netbeans/nbbuild/JarWithModuleAttributesTest.java
index 066d76adc5b2..c2f54802154d 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/JarWithModuleAttributesTest.java
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/JarWithModuleAttributesTest.java
@@ -21,16 +21,22 @@
import java.io.File;
import java.util.jar.JarFile;
import junit.framework.AssertionFailedError;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Rule;
/** Checks that javac.target gets reflected in the manifest.
*
* @author Jaroslav Tulach
*/
public class JarWithModuleAttributesTest extends TestBase {
+
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
+
public JarWithModuleAttributesTest (String name) {
super (name);
}
-
+
public void testAddThereVersionFromJavacTarget() throws Exception {
File output = new File(getWorkDir(), "output");
java.io.File manifest = extractString (
@@ -40,7 +46,7 @@ public void testAddThereVersionFromJavacTarget() throws Exception {
"OpenIDE-Module-Layer: org/netbeans/modules/sendopts/layer.xml\n"
);
File jar = new File(getWorkDir(), "x.jar");
-
+
java.io.File f = extractString (
"" +
"" +
@@ -59,8 +65,9 @@ public void testAddThereVersionFromJavacTarget() throws Exception {
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("JAR created", jar.isFile());
File extracted = new File(new File(output, "META-INF"), "MANIFEST.MF");
@@ -87,7 +94,7 @@ public void testKeepOldVersion() throws Exception {
"OpenIDE-Module-Layer: org/netbeans/modules/sendopts/layer.xml\n"
);
File jar = new File(getWorkDir(), "x.jar");
-
+
java.io.File f = extractString (
"" +
"" +
@@ -106,8 +113,9 @@ public void testKeepOldVersion() throws Exception {
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("JAR created", jar.isFile());
File extracted = new File(new File(output, "META-INF"), "MANIFEST.MF");
@@ -163,7 +171,8 @@ public void testKeepOldVersionForNetigso() throws Exception {
);
- execute (f, new String[] { "-verbose" });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertTrue ("JAR created", jar.isFile());
@@ -218,7 +227,7 @@ public void testIgnoreWeirdJavacTarget() throws Exception {
"OpenIDE-Module-Layer: org/netbeans/modules/sendopts/layer.xml\n"
);
File jar = new File(getWorkDir(), "x.jar");
-
+
java.io.File f = extractString (
"" +
"" +
@@ -237,8 +246,9 @@ public void testIgnoreWeirdJavacTarget() throws Exception {
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("JAR created", jar.isFile());
File extracted = new File(new File(output, "META-INF"), "MANIFEST.MF");
@@ -277,7 +287,8 @@ public void testExportPackage() throws Exception {
);
- execute (f, new String[] { "-verbose" });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertTrue ("JAR created", jar.isFile());
@@ -303,7 +314,7 @@ public void testExportPackage() throws Exception {
fail("Unwanted dependency on org.netbeans.libs.osgi:\n" + req);
}
}
-
+
private static void assertVersionAtLeast(String limit, String value) {
int[] segLimit = segments(limit);
int[] segValue = segments(value);
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/LocFilesTest.java b/nbbuild/test/unit/src/org/netbeans/nbbuild/LocFilesTest.java
index 5840dc646d09..34f6d6959814 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/LocFilesTest.java
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/LocFilesTest.java
@@ -35,7 +35,7 @@ public class LocFilesTest extends NbTestCase {
private File src;
private File dist;
private LocFiles task;
-
+
public LocFilesTest(String n) {
super(n);
}
@@ -47,7 +47,7 @@ protected void setUp() throws Exception {
dist.mkdirs();
src = new File(getWorkDir(), "src");
src.mkdirs();
-
+
Project p = new Project();
task = new LocFiles();
task.setProject(p);
@@ -57,7 +57,7 @@ protected void setUp() throws Exception {
task.setSrc(src);
task.setDestDir(dist);
}
-
+
public void testOpenideUtilLookup() throws Exception {
createSource("cs/platform/org-openide-util-lookup/netbeans/lib/org-openide-util-lookup/org/openide/util/lookup/Bundle_cs.properties");
task.setCodeNameBase("org.openide.util.lookup");
@@ -81,7 +81,7 @@ public void testSettingsPatternsOnly() throws Exception {
task.execute();
assertPattern("platform", "modules/locale/org-netbeans-modules-settings_cs.jar");
}
-
+
public void testCoreWindows() throws Exception {
final String pref = "cs/platform/org-netbeans-core-windows/org-netbeans-core-windows/org/netbeans/core/windows/";
createSource(
@@ -94,7 +94,7 @@ public void testCoreWindows() throws Exception {
);
task.setCodeNameBase("org.netbeans.core.windows");
task.execute();
- assertDist("platform/modules/locale/org-netbeans-core-windows_cs.jar",
+ assertDist("platform/modules/locale/org-netbeans-core-windows_cs.jar",
"org/netbeans/core/windows/resources/Bundle_cs.properties",
"org/netbeans/core/windows/actions/Bundle_cs.properties",
"org/netbeans/core/windows/services/Bundle_cs.properties",
@@ -104,7 +104,7 @@ public void testCoreWindows() throws Exception {
);
assertPattern("platform", "modules/locale/org-netbeans-core-windows_cs.jar");
}
-
+
public void testAutoupdateServices() throws Exception {
final String pref = "cs/platform/autoupdate-services/autoupdate-services/org/netbeans/modules/autoupdate/";
createSource(
@@ -115,18 +115,18 @@ public void testAutoupdateServices() throws Exception {
);
task.setCodeNameBase("org.netbeans.modules.autoupdate.services");
task.execute();
- assertDist("platform/modules/locale/org-netbeans-modules-autoupdate-services_cs.jar",
+ assertDist("platform/modules/locale/org-netbeans-modules-autoupdate-services_cs.jar",
"org/netbeans/modules/autoupdate/services/resources/Bundle_cs.properties",
"org/netbeans/modules/autoupdate/services/Bundle_cs.properties",
"org/netbeans/modules/autoupdate/updateprovider/Bundle_cs.properties"
);
- assertDist("platform/modules/ext/locale/updater_cs.jar",
+ assertDist("platform/modules/ext/locale/updater_cs.jar",
"org/netbeans/updater/Bundle_cs.properties"
);
assertPattern("platform", "modules/locale/org-netbeans-modules-autoupdate-services_cs.jar");
assertPattern("platform", "modules/ext/locale/updater_cs.jar");
}
-
+
public void testAnt() throws Exception {
task.setLocales("ja");
task.setCluster("java");
@@ -174,7 +174,7 @@ private void assertPattern(String cluster, String file) {
assertNotNull("Reference is found", ref);
assertTrue("Right instance: " + ref, ref instanceof PatternSet);
PatternSet ps = (PatternSet)ref;
-
+
List arr = Arrays.asList(ps.getIncludePatterns(task.getProject()));
assertTrue(file + " is there: " + arr, arr.contains(file));
}
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/MakeJNLPTest.java b/nbbuild/test/unit/src/org/netbeans/nbbuild/MakeJNLPTest.java
index 9537ab7b88e2..28796d015c4c 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/MakeJNLPTest.java
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/MakeJNLPTest.java
@@ -38,16 +38,33 @@
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Rule;
/** Is generation of Jnlp files correct?
*
* @author Jaroslav Tulach, Jesse Glick
*/
public class MakeJNLPTest extends TestBase {
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
+
public MakeJNLPTest (String name) {
super (name);
}
-
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ System.clearProperty("test.output");
+ System.clearProperty("test.parent");
+ System.clearProperty("test.name");
+ System.clearProperty("test.ks");
+ System.clearProperty("test.ext");
+ }
+
+
private static void assertFilenames(File dir, String... contents) {
assertTrue(dir + " is a directory", dir.isDirectory());
SortedSet expected = new TreeSet<>(Arrays.asList(contents));
@@ -64,10 +81,10 @@ private static void findFilenames(File dir, String prefix, Set names) {
}
}
}
-
+
public void testGenerateJNLPAndSignedJarForSimpleModule() throws Exception {
Manifest m;
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "org.my.module/3");
File simpleJar = generateJar (new String[0], m);
@@ -75,13 +92,13 @@ public void testGenerateJNLPAndSignedJarForSimpleModule() throws Exception {
File parent = simpleJar.getParentFile ();
File output = new File(parent, "output");
File ks = generateKeystore("jnlp", "netbeans-test");
-
+
java.io.File f = extractString (
"" +
"" +
" " +
"" +
- " " +
+ " " +
" " +
" " +
" " +
@@ -90,21 +107,22 @@ public void testGenerateJNLPAndSignedJarForSimpleModule() throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertFilenames(output, "org-my-module.jnlp", "org-my-module/s0.jar");
-
+
File jnlp = new File(output, "org-my-module.jnlp");
String res = readFile (jnlp);
-
+
assertTrue ("Component JNLP type: " + res, res.indexOf ("") >= 0);
assertTrue ("We support all permissions by default: " + res, res.indexOf ("") >= 0);
-
+
Matcher match = Pattern.compile(".*codebase=['\\\"]([^'\\\"]*)['\\\"]").matcher(res);
assertTrue("codebase is there", match.find());
assertEquals("one group found", 1, match.groupCount());
String base = match.group(1);
-
+
assertEquals("By default the dest directory is $$codebase: ", "$$codebase", base);
CHECK_SIGNED: {
@@ -146,8 +164,8 @@ public void testHandlesOSGi() throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertFilenames(output, "org-my-module.jnlp", "org-my-module/s0.jar");
File jnlp = new File(output, "org-my-module.jnlp");
@@ -166,7 +184,7 @@ public void testHandlesOSGi() throws Exception {
public void testGenerateJNLPAndUnSignedJarForSimpleModule() throws Exception {
Manifest m;
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "org.my.module/3");
File simpleJar = generateJar (new String[0], m);
@@ -174,13 +192,13 @@ public void testGenerateJNLPAndUnSignedJarForSimpleModule() throws Exception {
File parent = simpleJar.getParentFile ();
File output = new File(parent, "output");
File ks = generateKeystore("jnlp", "netbeans-test");
-
+
java.io.File f = extractString (
"" +
"" +
" " +
"" +
- " " +
+ " " +
" " +
" " +
" " +
@@ -189,21 +207,22 @@ public void testGenerateJNLPAndUnSignedJarForSimpleModule() throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertFilenames(output, "org-my-module.jnlp", "org-my-module/s0.jar");
-
+
File jnlp = new File(output, "org-my-module.jnlp");
String res = readFile (jnlp);
-
+
assertTrue ("Component JNLP type: " + res, res.indexOf ("") >= 0);
assertTrue ("We support all permissions by default: " + res, res.indexOf ("") >= 0);
-
+
Matcher match = Pattern.compile(".*codebase=['\\\"]([^'\\\"]*)['\\\"]").matcher(res);
assertTrue("codebase is there", match.find());
assertEquals("one group found", 1, match.groupCount());
String base = match.group(1);
-
+
assertEquals("By default the dest directory is $$codebase: ", "$$codebase", base);
File jar = new File(output, "org-my-module/s0.jar");
@@ -215,7 +234,7 @@ public void testGenerateJNLPAndUnSignedJarForSimpleModule() throws Exception {
fail ("File should not be signed: " + jar);
}
}
-
+
}
public void testGenerateMacOSOnlySimpleModule() throws Exception {
@@ -232,10 +251,10 @@ public void testGenerateWindowsOSOnlySimpleModule() throws Exception {
public void testGenerateSolarisOSOnlySimpleModule() throws Exception {
doGenerateOSOnlySimpleModule("org.openide.modules.os.Solaris", "");
}
-
+
private void doGenerateOSOnlySimpleModule(String tok, String find) throws Exception {
Manifest m;
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "org.my.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Requires", tok + ", pepa.z.bota");
@@ -244,13 +263,13 @@ private void doGenerateOSOnlySimpleModule(String tok, String find) throws Except
File parent = simpleJar.getParentFile ();
File output = new File(parent, "output");
File ks = generateKeystore("jnlp", "netbeans-test");
-
+
java.io.File f = extractString (
"" +
"" +
" " +
"" +
- " " +
+ " " +
" " +
" " +
" " +
@@ -259,22 +278,23 @@ private void doGenerateOSOnlySimpleModule(String tok, String find) throws Except
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertFilenames(output, "org-my-module.jnlp", "org-my-module/s0.jar");
-
+
File jnlp = new File(output, "org-my-module.jnlp");
String res = readFile (jnlp);
-
+
assertTrue ("Component JNLP type: " + res, res.indexOf ("") >= 0);
assertTrue ("Resource is os dependant: " + res, res.indexOf (find) >= 0);
assertTrue ("We support all permissions by default: " + res, res.indexOf ("") >= 0);
-
+
Matcher match = Pattern.compile(".*codebase=['\\\"]([^'\\\"]*)['\\\"]").matcher(res);
assertTrue("codebase is there", match.find());
assertEquals("one group found", 1, match.groupCount());
String base = match.group(1);
-
+
assertEquals("By default the dest directory is $$codebase: ", "$$codebase", base);
File jar = new File(output, "org-my-module/s0.jar");
@@ -286,11 +306,11 @@ private void doGenerateOSOnlySimpleModule(String tok, String find) throws Except
fail ("File should not be signed: " + jar);
}
}
-
+
}
-
+
public void testTheLocalizedAutoupdateProblem() throws Exception {
- String UTfile =
+ String UTfile =
"" +
"" +
" " +
@@ -303,22 +323,22 @@ public void testTheLocalizedAutoupdateProblem() throws Exception {
" " +
" " +
"";
-
+
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "org.netbeans.modules.autoupdate/1");
m.getMainAttributes ().putValue ("Class-Path", "ext/updater.jar");
File simpleJar = generateJar ("modules/", new String[0], m, null);
File moduleJar = new File(simpleJar.getParentFile(), "org-netbeans-modules-autoupdate.jar");
simpleJar.renameTo(moduleJar);
-
+
File p = simpleJar.getParentFile();
-
+
simpleJar = generateJar ("modules/locale/", new String[0], createManifest(), null);
simpleJar.renameTo(new File(simpleJar.getParentFile(), "org-netbeans-modules-autoupdate_ja.jar"));
simpleJar = generateJar ("modules/locale/", new String[0], createManifest(), null);
simpleJar.renameTo(new File(simpleJar.getParentFile(), "org-netbeans-modules-autoupdate_zh_CN.jar"));
-
+
simpleJar = generateJar ("modules/ext/", new String[0], createManifest(), null);
simpleJar.renameTo(new File(simpleJar.getParentFile(), "updater.jar"));
@@ -331,11 +351,11 @@ public void testTheLocalizedAutoupdateProblem() throws Exception {
File xml = new File(p, "config/Modules/org-netbeans-modules-autoupdate.xml");
xml.getParentFile().mkdirs();
xml.createNewFile();
-
+
File updateTracking = new File(getWorkDir(), "update_tracking");
updateTracking.mkdirs();
assertTrue("Created", updateTracking.isDirectory());
-
+
File trackingFile = new File(updateTracking, "org-netbeans-modules-autoupdate.xml");
try (FileWriter w = new FileWriter(trackingFile)) {
w.write(UTfile);
@@ -343,13 +363,13 @@ public void testTheLocalizedAutoupdateProblem() throws Exception {
File output = new File(getWorkDir(), "output");
File ks = generateKeystore("jnlp", "netbeans-test");
-
+
java.io.File f = extractString (
"" +
"" +
" " +
"" +
- " " +
+ " " +
" " +
" " +
" " +
@@ -358,8 +378,9 @@ public void testTheLocalizedAutoupdateProblem() throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertFilenames(output, "org-netbeans-modules-autoupdate.jnlp",
"org-netbeans-modules-autoupdate/org-netbeans-modules-autoupdate.jar",
"org-netbeans-modules-autoupdate/locale-org-netbeans-modules-autoupdate_zh_CN.jar",
@@ -367,21 +388,21 @@ public void testTheLocalizedAutoupdateProblem() throws Exception {
"org-netbeans-modules-autoupdate/ext-locale-updater_zh_CN.jar",
"org-netbeans-modules-autoupdate/ext-locale-updater_ja.jar",
"org-netbeans-modules-autoupdate/ext-updater.jar");
-
+
File jnlp = new File(output, "org-netbeans-modules-autoupdate.jnlp");
String res = readFile (jnlp);
-
-
+
+
assertTrue ("Component JNLP type: " + res, res.indexOf ("") >= 0);
assertTrue ("We support all permissions by default: " + res, res.indexOf ("") >= 0);
-
+
Matcher match = Pattern.compile(".*codebase=['\\\"]([^'\\\"]*)['\\\"]").matcher(res);
assertTrue("codebase is there", match.find());
assertEquals("one group found", 1, match.groupCount());
String base = match.group(1);
-
+
assertEquals("By default the dest directory is $$codebase: ", "$$codebase", base);
-
+
assertResource(res, "ja", "org-netbeans-modules-autoupdate/ext-locale-updater_ja.jar");
assertResource(res, "zh_CN", "org-netbeans-modules-autoupdate/ext-locale-updater_zh_CN.jar");
assertResource(res, "ja", "org-netbeans-modules-autoupdate/locale-org-netbeans-modules-autoupdate_ja.jar");
@@ -401,11 +422,11 @@ public void testTheLocalizedAutoupdateProblem() throws Exception {
}
fail ("File does not seem to be signed: " + jar);
}
-
+
}
public void testGenerateJNLPForMissingRegularModule() throws Exception {
Manifest m;
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "org.netbeans.core.startup");
File simpleJar = generateJar ("modules/", new String[0], m, null);
@@ -416,11 +437,11 @@ public void testGenerateJNLPForMissingRegularModule() throws Exception {
File parent = simpleJar.getParentFile ();
File localizedJarCZ = generateJar("modules/locale/", new String[0], createManifest(), null);
assertTrue("Successful rename", localizedJarCZ.renameTo(new File(localizedJarCZ.getParent(), "core_cs.jar")));
-
+
File updateTracking = new File(getWorkDir(), "update_tracking");
updateTracking.mkdirs();
assertTrue("Created", updateTracking.isDirectory());
-
+
File trackingFile = new File(updateTracking, "org-netbeans-core-startup.xml");
try (FileWriter w = new FileWriter(trackingFile)) {
w.write(
@@ -436,17 +457,17 @@ public void testGenerateJNLPForMissingRegularModule() throws Exception {
"\n"
);
}
-
-
+
+
File output = new File(parent, "output");
File ks = generateKeystore("jnlp", "netbeans-test");
-
+
java.io.File f = extractString (
"" +
"" +
" " +
"" +
- " " +
+ " " +
" " +
" " +
" " +
@@ -455,16 +476,17 @@ public void testGenerateJNLPForMissingRegularModule() throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertFilenames(output, "org-netbeans-core-startup.jnlp",
"org-netbeans-core-startup/core.jar",
"org-netbeans-core-startup/locale-core_cs.jar");
}
-
+
public void testGenerateJNLPAndSignedJarForSimpleLocalizedModule() throws Exception {
Manifest m;
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "org.my.module/3");
File simpleJar = generateJar ("modules/", new String[0], m, null);
@@ -473,11 +495,11 @@ public void testGenerateJNLPAndSignedJarForSimpleLocalizedModule() throws Except
File localizedJarCZ = generateJar("modules/locale/", new String[0], createManifest(), null);
assertEquals("There need to have the same name", simpleJar.getName(), localizedJarCZ.getName());
assertTrue("Successful rename", localizedJarCZ.renameTo(new File(localizedJarCZ.getParent(), "0_cs.jar")));
-
+
File localizedJarZH = generateJar("modules/locale/", new String[0], createManifest(), null);
assertEquals("There need to have the same name", simpleJar.getName(), localizedJarZH.getName());
assertTrue("Successful rename", localizedJarZH.renameTo(new File(localizedJarCZ.getParent(), "0_zh_CN.jar")));
-
+
File localizedJarJA = generateJar("modules/locale/", new String[0], createManifest(), null);
assertEquals("There need to have the same name", simpleJar.getName(), localizedJarJA.getName());
assertTrue("Successful rename", localizedJarJA.renameTo(new File(localizedJarCZ.getParent(), "0_ja.jar")));
@@ -485,7 +507,7 @@ public void testGenerateJNLPAndSignedJarForSimpleLocalizedModule() throws Except
File updateTracking = new File(getWorkDir(), "update_tracking");
updateTracking.mkdirs();
assertTrue("Created", updateTracking.isDirectory());
-
+
File trackingFile = new File(updateTracking, "org-my-module.xml");
try (FileWriter w = new FileWriter(trackingFile)) {
w.write(
@@ -501,17 +523,17 @@ public void testGenerateJNLPAndSignedJarForSimpleLocalizedModule() throws Except
"\n"
);
}
-
-
+
+
File output = new File(parent, "output");
File ks = generateKeystore("jnlp", "netbeans-test");
-
+
java.io.File f = extractString (
"" +
"" +
" " +
"" +
- " " +
+ " " +
" " +
" " +
" " +
@@ -520,7 +542,8 @@ public void testGenerateJNLPAndSignedJarForSimpleLocalizedModule() throws Except
"" +
""
);
- execute (f, new String[] { "-verbose" });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertFilenames(output, "org-my-module.jnlp",
"org-my-module/0.jar",
@@ -530,17 +553,17 @@ public void testGenerateJNLPAndSignedJarForSimpleLocalizedModule() throws Except
File jnlp = new File(output, "org-my-module.jnlp");
String res = readFile (jnlp);
-
+
assertTrue ("Component JNLP type: " + res, res.indexOf ("") >= 0);
assertTrue ("We support all permissions by default: " + res, res.indexOf ("") >= 0);
-
+
Matcher match = Pattern.compile(".*codebase=['\\\"]([^'\\\"]*)['\\\"]").matcher(res);
assertTrue("codebase is there", match.find());
assertEquals("one group found", 1, match.groupCount());
String base = match.group(1);
-
+
assertEquals("By default the dest directory is $$codebase: ", "$$codebase", base);
-
+
assertResource(res, "cs", "org-my-module/locale-0_cs.jar");
assertResource(res, "ja", "org-my-module/locale-0_ja.jar");
assertResource(res, "zh_CN", "org-my-module/locale-0_zh_CN.jar");
@@ -549,7 +572,7 @@ public void testGenerateJNLPAndSignedJarForSimpleLocalizedModule() throws Except
if (!jar.getName().endsWith(".jar")) {
continue;
}
-
+
JarFile signed = new JarFile(jar);
Enumeration it = signed.entries();
while (it.hasMoreElements()) {
@@ -563,7 +586,7 @@ public void testGenerateJNLPAndSignedJarForSimpleLocalizedModule() throws Except
}
public void testGenerateJNLPForMissingCoreIssue103301() throws Exception {
Manifest m;
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "org.netbeans.core.startup");
File simpleJar = generateJar ("core/", new String[0], m, null);
@@ -574,11 +597,11 @@ public void testGenerateJNLPForMissingCoreIssue103301() throws Exception {
File parent = simpleJar.getParentFile ();
File localizedJarCZ = generateJar("core/locale/", new String[0], createManifest(), null);
assertTrue("Successful rename", localizedJarCZ.renameTo(new File(localizedJarCZ.getParent(), "core_cs.jar")));
-
+
File updateTracking = new File(getWorkDir(), "update_tracking");
updateTracking.mkdirs();
assertTrue("Created", updateTracking.isDirectory());
-
+
File trackingFile = new File(updateTracking, "org-netbeans-core-startup.xml");
try (FileWriter w = new FileWriter(trackingFile)) {
w.write(
@@ -594,17 +617,17 @@ public void testGenerateJNLPForMissingCoreIssue103301() throws Exception {
"\n"
);
}
-
-
+
+
File output = new File(parent, "output");
File ks = generateKeystore("jnlp", "netbeans-test");
-
+
java.io.File f = extractString (
"" +
"" +
" " +
"" +
- " " +
+ " " +
" " +
" " +
" " +
@@ -613,16 +636,17 @@ public void testGenerateJNLPForMissingCoreIssue103301() throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertFilenames(output, "org-netbeans-core-startup.jnlp",
"org-netbeans-core-startup/core.jar",
"org-netbeans-core-startup/locale-core_cs.jar");
}
-
+
public void testGenerateJNLPAndUnSignedJarForSimpleLocalizedModule() throws Exception {
Manifest m;
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "org.my.module/3");
File simpleJar = generateJar ("modules/", new String[0], m, null);
@@ -631,11 +655,11 @@ public void testGenerateJNLPAndUnSignedJarForSimpleLocalizedModule() throws Exce
File localizedJarCZ = generateJar("modules/locale/", new String[0], createManifest(), null);
assertEquals("There need to have the same name", simpleJar.getName(), localizedJarCZ.getName());
assertTrue("Successful rename", localizedJarCZ.renameTo(new File(localizedJarCZ.getParent(), "0_cs.jar")));
-
+
File localizedJarZH = generateJar("modules/locale/", new String[0], createManifest(), null);
assertEquals("There need to have the same name", simpleJar.getName(), localizedJarZH.getName());
assertTrue("Successful rename", localizedJarZH.renameTo(new File(localizedJarCZ.getParent(), "0_zh_CN.jar")));
-
+
File localizedJarJA = generateJar("modules/locale/", new String[0], createManifest(), null);
assertEquals("There need to have the same name", simpleJar.getName(), localizedJarJA.getName());
assertTrue("Successful rename", localizedJarJA.renameTo(new File(localizedJarCZ.getParent(), "0_ja.jar")));
@@ -643,7 +667,7 @@ public void testGenerateJNLPAndUnSignedJarForSimpleLocalizedModule() throws Exce
File updateTracking = new File(getWorkDir(), "update_tracking");
updateTracking.mkdirs();
assertTrue("Created", updateTracking.isDirectory());
-
+
File trackingFile = new File(updateTracking, "org-my-module.xml");
try (FileWriter w = new FileWriter(trackingFile)) {
w.write(
@@ -659,17 +683,17 @@ public void testGenerateJNLPAndUnSignedJarForSimpleLocalizedModule() throws Exce
"\n"
);
}
-
-
+
+
File output = new File(parent, "output");
File ks = generateKeystore("jnlp", "netbeans-test");
-
+
java.io.File f = extractString (
"" +
"" +
" " +
"" +
- " " +
+ " " +
" " +
" " +
" " +
@@ -678,7 +702,8 @@ public void testGenerateJNLPAndUnSignedJarForSimpleLocalizedModule() throws Exce
"" +
""
);
- execute (f, new String[] { "-verbose" });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertFilenames(output, "org-my-module.jnlp",
"org-my-module/0.jar",
@@ -688,17 +713,17 @@ public void testGenerateJNLPAndUnSignedJarForSimpleLocalizedModule() throws Exce
File jnlp = new File(output, "org-my-module.jnlp");
String res = readFile (jnlp);
-
+
assertTrue ("Component JNLP type: " + res, res.indexOf ("") >= 0);
assertTrue ("We support all permissions by default: " + res, res.indexOf ("") >= 0);
-
+
Matcher match = Pattern.compile(".*codebase=['\\\"]([^'\\\"]*)['\\\"]").matcher(res);
assertTrue("codebase is there", match.find());
assertEquals("one group found", 1, match.groupCount());
String base = match.group(1);
-
+
assertEquals("By default the dest directory is $$codebase: ", "$$codebase", base);
-
+
assertResource(res, "cs", "org-my-module/locale-0_cs.jar");
assertResource(res, "ja", "org-my-module/locale-0_ja.jar");
assertResource(res, "zh_CN", "org-my-module/locale-0_zh_CN.jar");
@@ -707,7 +732,7 @@ public void testGenerateJNLPAndUnSignedJarForSimpleLocalizedModule() throws Exce
if (!jar.getName().endsWith(".jar")) {
continue;
}
-
+
JarFile signed = new JarFile(jar);
Enumeration it = signed.entries();
while (it.hasMoreElements()) {
@@ -718,16 +743,16 @@ public void testGenerateJNLPAndUnSignedJarForSimpleLocalizedModule() throws Exce
}
}
}
-
+
private static void assertResource(String where, String locale, String file) {
where = where.replace('\n', ' ');
Matcher match = Pattern.compile(".*.*").matcher(where);
assertTrue("File really referenced " + file + " in locale " + locale + "\n" + where, match.find());
}
-
+
public void testOneCanChangeTheCodeBase() throws Exception {
Manifest m;
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "org.my.module/3");
File simpleJar = generateJar (new String[0], m);
@@ -735,13 +760,13 @@ public void testOneCanChangeTheCodeBase() throws Exception {
File parent = simpleJar.getParentFile ();
File output = new File(parent, "output");
File ks = generateKeystore("jnlp", "netbeans-test");
-
+
java.io.File f = extractString (
"" +
"" +
" " +
"" +
- " " +
+ " " +
" " +
" " +
" " +
@@ -750,22 +775,23 @@ public void testOneCanChangeTheCodeBase() throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertFilenames(output, "org-my-module.jnlp",
"org-my-module/s0.jar");
-
+
File jnlp = new File(output, "org-my-module.jnlp");
String res = readFile (jnlp);
-
+
assertTrue ("Component JNLP type: " + res, res.indexOf ("") >= 0);
assertTrue ("We support all permissions by default: " + res, res.indexOf ("") >= 0);
-
+
Matcher match = Pattern.compile(".*codebase=['\\\"]([^'\\\"]*)['\\\"]").matcher(res);
assertTrue("codebase is there", match.find());
assertEquals("one group found", 1, match.groupCount());
String base = match.group(1);
-
+
assertEquals("By default the codebases can be changed: ", "http://www.my.org/", base);
}
@@ -775,7 +801,7 @@ public void testGenerateJNLPAndSignedJarForModuleWithClassPath() throws Exceptio
"" +
" " +
"" +
- " " +
+ " " +
" " +
" " +
" " +
@@ -784,13 +810,13 @@ public void testGenerateJNLPAndSignedJarForModuleWithClassPath() throws Exceptio
"" +
""
);
-
+
assertFilenames(output, "aaa-my-module.jnlp", "aaa-my-module/ext-t0.jar", "aaa-my-module/s0.jar");
-
+
File jnlp = new File(output, "aaa-my-module.jnlp");
String res = readFile (jnlp);
-
+
Matcher m = Pattern.compile("").matcher(res);
for (int x = 0; x < 2; x++) {
assertTrue("Matches at least one" + "(" + x + ")", m.find());
@@ -798,18 +824,18 @@ public void testGenerateJNLPAndSignedJarForModuleWithClassPath() throws Exceptio
File f = new File (jnlp.getParentFile(), m.group(1));
assertTrue("The file " + f + " exists" + "(" + x + ")", f.exists());
}
-
+
}
public void testGenerateJNLPAndSignedJarForModuleWithClassPathAndSignedJar() throws Exception {
File ks = generateKeystore("external", "netbeans-test");
-
+
File output = doClassPathModuleCheck(
"" +
"" +
" " +
"" +
- " " +
+ " " +
" \n" +
" " +
" " +
@@ -819,11 +845,11 @@ public void testGenerateJNLPAndSignedJarForModuleWithClassPathAndSignedJar() thr
"" +
""
);
-
+
assertFilenames(output, "aaa-my-module.jnlp", "aaa-my-module/s0.jar",
"aaa-my-module/ext-t0.jar",
"aaa-my-module-ext-t0.jnlp");
-
+
JarFile f = new JarFile(new File(output, "aaa-my-module/ext-t0.jar"));
Enumeration en = f.entries();
StringBuffer sb = new StringBuffer();
@@ -843,45 +869,45 @@ public void testGenerateJNLPAndSignedJarForModuleWithClassPathAndSignedJar() thr
if (cnt == 0) {
fail("Signed with wrong file:\n" + sb);
}
-
+
File jnlp = new File(output, "aaa-my-module.jnlp");
-
+
String res = readFile (jnlp);
int first = res.indexOf("jar href");
assertEquals("Just one jar href ", -1, res.indexOf("jar href", first + 1));
-
+
String extRes = readFile(new File(output, "aaa-my-module-ext-t0.jnlp"));
-
+
Matcher m = Pattern.compile("(.*)").matcher(extRes);
assertTrue("title is there: " + extRes, m.find());
assertEquals("Name of file is used for title", "t0", m.group(1));
}
-
+
public void testInformationIsTakenFromLocalizedBundle() throws Exception {
Manifest m;
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "org.my.module/3");
-
+
Properties props = new Properties();
props.put("OpenIDE-Module-Name", "Module Build Harness");
props.put("OpenIDE-Module-Display-Category", "Developing NetBeans");
props.put("OpenIDE-Module-Short-Description", "Lets you build external plug-in modules from sources.");
props.put("OpenIDE-Module-Long-Description", "XXX");
-
+
File simpleJar = generateJar (null, new String[0], m, props);
File parent = simpleJar.getParentFile ();
File output = new File(parent, "output");
File ks = generateKeystore("jnlp", "netbeans-test");
-
+
java.io.File f = extractString (
"" +
"" +
" " +
"" +
- " " +
+ " " +
" " +
" " +
" " +
@@ -890,35 +916,36 @@ public void testInformationIsTakenFromLocalizedBundle() throws Exception {
"" +
""
);
- execute (f, new String[] { });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertFilenames(output, "org-my-module.jnlp", "org-my-module/s0.jar");
-
+
File jnlp = new File(output, "org-my-module.jnlp");
String res = readFile (jnlp);
int infoBegin = res.indexOf("");
int infoEnd = res.indexOf("");
-
+
if (infoEnd == -1 || infoBegin == -1) {
fail ("Both information tags must be present: " + res);
}
-
+
String info = res.substring(infoBegin, infoEnd);
-
+
if (info.indexOf("Module Build Harness") == -1) {
fail("Title should be there with Module Build Harness inside itself: " + info);
}
-
+
if (info.indexOf("Lets you build external plug-in modules from sources.") == -1) {
fail("one-line should be there with 'lets you...' inside itself: " + info);
}
-
+
if (info.indexOf("XXX") == -1) {
fail("short should be there with XXX inside itself: " + info);
}
}
-
+
public void testGenerateJNLPFailsForModulesWithExtraFiles() throws Exception {
doCompareJNLPFileWithUpdateTracking(true, null, "");
}
@@ -931,14 +958,14 @@ public void testGenerateJNLPSucceedsWhenExtraFileIsExcluded() throws Exception {
public void testGenerateJNLPSucceedsWhenModuleAutoDepsArePresent() throws Exception {
doCompareJNLPFileWithUpdateTracking(false, "config/ModuleAutoDeps/aaa-my-module.xml", " verifyexcludes=' none ' ");
}
-
+
private void doCompareJNLPFileWithUpdateTracking(boolean useNonModule, String fakeEntry, String extraScript) throws Exception {
File nonModule = generateJar (new String[0], createManifest());
-
+
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "aaa.my.module/3");
File module = generateJar (new String[0], m);
-
+
File updateTracking = new File(getWorkDir(), "update_tracking");
updateTracking.mkdirs();
assertTrue("Created", updateTracking.isDirectory());
@@ -946,7 +973,7 @@ private void doCompareJNLPFileWithUpdateTracking(boolean useNonModule, String fa
File enableXML = new File(new File(getWorkDir(), "config"), "Modules");
enableXML.getParentFile().mkdirs();
enableXML.createNewFile();
-
+
File trackingFile = new File(updateTracking, "aaa-my-module.xml");
try (FileWriter w = new FileWriter(trackingFile)) {
w.write(
@@ -961,15 +988,15 @@ private void doCompareJNLPFileWithUpdateTracking(boolean useNonModule, String fa
"\n"
);
}
-
-
-
+
+
+
String script =
"" +
"" +
" " +
"" +
- " " +
+ " " +
" " +
" " +
" " +
@@ -979,22 +1006,29 @@ private void doCompareJNLPFileWithUpdateTracking(boolean useNonModule, String fa
"";
assertEquals("Both modules in the same dir", module.getParentFile(), nonModule.getParentFile());
-
+
File output = new File(getWorkDir(), "output");
File ks = generateKeystore("jnlp", "netbeans-test");
-
+
java.io.File f = extractString (script);
try {
- execute (f, new String[] {
- "-Dtest.output=" + output,
- "-Dtest.parent=" + module.getParent(),
+ System.setProperty("test.output", output.getAbsolutePath());
+ System.setProperty("test.parent", module.getParentFile().getAbsolutePath());
+ System.setProperty("test.name", module.getName());
+ System.setProperty("test.ks", ks.getAbsolutePath());
+
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+ /*execute (f, new String[] {
+ "-Dtest.output=" + output,
+ "-Dtest.parent=" + module.getParent(),
"-Dtest.name=" + module.getName(),
"-Dtest.ks=" + ks,
- });
+ });*/
if (useNonModule) {
- fail("The task has to fail");
+ fail("The task has to fail");
}
-
+
assertTrue ("Output exists", output.exists ());
assertTrue ("Output directory created", output.isDirectory());
@@ -1003,7 +1037,7 @@ private void doCompareJNLPFileWithUpdateTracking(boolean useNonModule, String fa
String[] files = ext.getParentFile().list();
assertEquals("Two files are there", 2, files.length);
- } catch (ExecutionError ex) {
+ } catch (BuildException ex) {
if (!useNonModule) {
throw ex;
} else {
@@ -1018,46 +1052,53 @@ private void doCompareJNLPFileWithUpdateTracking(boolean useNonModule, String fa
assertEquals("Output dir is empty as nothing has been generated", 0, files.length);
}
}
-
+
}
private File doClassPathModuleCheck(String script) throws Exception {
Manifest m;
File extJar = generateJar ("modules/ext", new String[0], createManifest(), null);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "aaa.my.module/3");
m.getMainAttributes ().putValue ("Class-Path", "ext/" + extJar.getName());
File simpleJar = generateJar ("modules", new String[0], m, null);
File parent = simpleJar.getParentFile ();
-
+
File output = new File(parent, "output");
File ks = generateKeystore("jnlp", "netbeans-test");
-
+
java.io.File f = extractString (script);
- execute (f, new String[] {
- "-Dtest.output=" + output,
- "-Dtest.parent=" + parent,
+/* execute (f, new String[] {
+ "-Dtest.output=" + output,
+ "-Dtest.parent=" + parent,
"-Dtest.name=" + simpleJar.getName(),
"-Dtest.ks=" + ks,
"-Dtest.ext=" + extJar
- });
-
+ });*/
+ System.setProperty("test.output", output.getAbsolutePath());
+ System.setProperty("test.parent", parent.getAbsolutePath());
+ System.setProperty("test.name", simpleJar.getName());
+ System.setProperty("test.ks", ks.getAbsolutePath());
+ System.setProperty("test.ext", extJar.getAbsolutePath());
+
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
return output;
}
-
-
+
+
private File createNewJarFile(String prefix) throws IOException {
if (prefix == null) {
prefix = "modules";
}
String ss = prefix.substring(prefix.length()-1);
-
+
File dir = new File(this.getWorkDir(), prefix);
dir.mkdirs();
-
+
int i = 0;
for (;;) {
File f = new File (dir, ss + i++ + ".jar");
@@ -1066,43 +1107,43 @@ private File createNewJarFile(String prefix) throws IOException {
}
}
}
-
+
protected final File generateJar (String[] content, Manifest manifest) throws IOException {
return generateJar(null, content, manifest, null);
}
-
+
protected final File generateJar (String prefix, String[] content, Manifest manifest, Properties props) throws IOException {
File f = createNewJarFile (prefix);
-
+
if (props != null) {
manifest.getMainAttributes().putValue("OpenIDE-Module-Localizing-Bundle", "some/fake/prop/name/Bundle.properties");
}
-
+
try (JarOutputStream os = new JarOutputStream (new FileOutputStream (f), manifest)) {
if (props != null) {
os.putNextEntry(new JarEntry("some/fake/prop/name/Bundle.properties"));
props.store(os, "# properties for the module");
os.closeEntry();
}
-
-
+
+
for (int i = 0; i < content.length; i++) {
os.putNextEntry(new JarEntry (content[i]));
os.closeEntry();
}
os.closeEntry ();
}
-
+
return f;
}
-
+
@SuppressWarnings("SleepWhileInLoop")
private File generateKeystore(String alias, String password) throws Exception {
- Error lastEx = null;
+ BuildException lastEx = null;
for (int i = 0; i < 10; i++) {
File where = new File(getWorkDir(), "key" + i + ".ks");
- String script =
+ String script =
"" +
"" +
"" +
@@ -1111,13 +1152,15 @@ private File generateKeystore(String alias, String password) throws Exception {
"keystore='" + where + "' \n" +
"storepass='" + password + "' \n" +
"dname='CN=A NetBeans Friend, OU=NetBeans, O=netbeans.org, C=US' \n" +
+ "keyalg='DSA' \n" +
"/>\n" +
"\n";
java.io.File f = extractString (script);
try {
- execute (f, new String[] { });
- } catch (ExecutionError ex) {
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+ } catch (BuildException ex) {
Logger.getAnonymousLogger().log(Level.WARNING, "Failed for " + i, ex);
lastEx = ex;
if (ex.getMessage().indexOf("CKR_KEY_SIZE_RANGE") >= 0) {
@@ -1156,7 +1199,8 @@ public void testIndirectJars() throws Exception {
"" +
""
);
- execute(f, new String[] { "-verbose" });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertFilenames(output, "me.jnlp", "me/s0.jar", "me/lib-b0.jar");
File jnlp = new File(output, "me.jnlp");
String res = readFile(jnlp);
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/MakeMasterJNLPTest.java b/nbbuild/test/unit/src/org/netbeans/nbbuild/MakeMasterJNLPTest.java
index 5477b47859ff..8acd5deaf4f4 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/MakeMasterJNLPTest.java
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/MakeMasterJNLPTest.java
@@ -25,16 +25,22 @@
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Rule;
/** Is generation of Jnlp files correct?
*
* @author Jaroslav Tulach
*/
public class MakeMasterJNLPTest extends TestBase {
+
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
+
public MakeMasterJNLPTest (String name) {
super (name);
}
-
+
public void testOSGiModule() throws Exception {
int cnt = 3;
Manifest m;
@@ -68,7 +74,8 @@ public void testOSGiModule() throws Exception {
""
);
while (cnt-- > 0) {
- execute (f, new String[] { "-verbose" });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
}
assertTrue ("Output exists", output.exists ());
@@ -91,17 +98,17 @@ public void testOSGiModule() throws Exception {
assertExt(res1, "org.my.module");
assertExt(res2, "org.second.module");
}
-
+
public void testGenerateReferenceFilesOnce() throws Exception {
doGenerateReferenceFiles(1);
}
public void testGenerateReferenceFilesThrice() throws Exception {
doGenerateReferenceFiles(3);
}
-
+
private void doGenerateReferenceFiles(int cnt) throws Exception {
Manifest m;
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "org.my.module/3");
File simpleJar = generateJar (new String[0], m);
@@ -109,18 +116,18 @@ private void doGenerateReferenceFiles(int cnt) throws Exception {
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "org.second.module/3");
File secondJar = generateJar (new String[0], m);
-
+
File parent = simpleJar.getParentFile ();
assertEquals("They are in the same folder", parent, secondJar.getParentFile());
-
+
File output = new File(parent, "output");
-
+
java.io.File f = extractString (
"" +
"" +
" " +
"" +
- " " +
+ " " +
" " +
" " +
" " +
@@ -131,36 +138,37 @@ private void doGenerateReferenceFiles(int cnt) throws Exception {
""
);
while (cnt-- > 0) {
- execute (f, new String[] { "-verbose" });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
}
-
+
assertTrue ("Output exists", output.exists ());
assertTrue ("Output directory created", output.isDirectory());
-
+
String[] files = output.list();
assertEquals("It has two files", 2, files.length);
java.util.Arrays.sort(files);
-
+
assertEquals("The res1 file: " + files[0], "org-my-module.ref", files[0]);
assertEquals("The res2 file: "+ files[1], "org-second-module.ref", files[1]);
-
+
File r1 = new File(output, "org-my-module.ref");
String res1 = readFile (r1);
File r2 = new File(output, "org-second-module.ref");
String res2 = readFile (r2);
-
+
assertExt(res1, "org.my.module");
assertExt(res2, "org.second.module");
}
-
+
private static void assertExt(String res, String module) {
int ext = res.indexOf("";
w.write(UTfile);
}
-
+
java.io.File f = extractString (
"" +
"" +
" " +
"" +
- " " +
+ " " +
" " +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Output exists", output.exists ());
assertTrue ("Output directory created", output.isDirectory());
-
+
String[] files = output.list();
assertEquals("It has the nbm file", 1, files.length);
-
+
if (!files[0].endsWith("x.nbm")) {
fail("Not the right one: " + files[0]);
}
long time = output.listFiles()[0].lastModified();
-
+
// wait a while so the NBM file has different timestamp
// if recreated
Thread.sleep(1300);
// execute once again
- execute (f, new String[] { "-debug", "-Ddo.fail=true"});
-
+ System.setProperty("do.fail","true");
+ buildRule.configureProject(f.getAbsolutePath(),Project.MSG_DEBUG);
+ buildRule.executeTarget("all");
+
long newTime = output.listFiles()[0].lastModified();
-
- assertEquals("The file has not been modified:\n" + getStdOut(), time, newTime);
-
-
+
+ assertEquals("The file has not been modified:\n" + buildRule.getFullLog(), time, newTime);
+
+
CHECK_SIGNED: {
File jar = output.listFiles()[0];
JarFile signed = new JarFile(jar);
@@ -129,18 +145,18 @@ public void testGenerateNBMForSimpleModule() throws Exception {
}
fail ("File does not seem to be signed: " + jar);
}
-
+
}
-
+
private File createNewJarFile(String prefix) throws IOException {
if (prefix == null) {
prefix = "modules";
}
String ss = prefix.substring(prefix.length()-1);
-
+
File dir = new File(this.getWorkDir(), prefix);
dir.mkdirs();
-
+
int i = 0;
for (;;) {
File f = new File (dir, ss + i++ + ".jar");
@@ -149,40 +165,40 @@ private File createNewJarFile(String prefix) throws IOException {
}
}
}
-
+
protected final File generateJar (String[] content, Manifest manifest) throws IOException {
return generateJar(null, content, manifest, null);
}
-
+
protected final File generateJar (String prefix, String[] content, Manifest manifest, Properties props) throws IOException {
File f = createNewJarFile (prefix);
-
+
if (props != null) {
manifest.getMainAttributes().putValue("OpenIDE-Module-Localizing-Bundle", "some/fake/prop/name/Bundle.properties");
}
-
+
try (JarOutputStream os = new JarOutputStream (new FileOutputStream (f), manifest)) {
if (props != null) {
os.putNextEntry(new JarEntry("some/fake/prop/name/Bundle.properties"));
props.store(os, "# properties for the module");
os.closeEntry();
}
-
-
+
+
for (int i = 0; i < content.length; i++) {
os.putNextEntry(new JarEntry (content[i]));
os.closeEntry();
}
os.closeEntry ();
}
-
+
return f;
}
-
+
private File generateKeystore(String alias, String password) throws Exception {
File where = new File(getWorkDir(), "key.ks");
-
- String script =
+
+ String script =
"" +
"" +
"" +
@@ -191,13 +207,15 @@ private File generateKeystore(String alias, String password) throws Exception {
"keystore='" + where + "' \n" +
"storepass='" + password + "' \n" +
"dname='CN=A NetBeans Friend, OU=NetBeans, O=netbeans.org, C=US' \n" +
+ "keyalg='DSA' \n" +
"/>\n" +
"\n";
-
+
java.io.File f = extractString (script);
try {
- execute (f, new String[] { });
- } catch (ExecutionError err) {
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+ } catch (BuildException err) {
if (err.getMessage().indexOf("java.security.ProviderException") != -1) {
// common error on Sun OS:
// org.netbeans.nbbuild.PublicPackagesInProjectizedXMLTest$ExecutionError: Execution has to finish without problems was: 1
@@ -209,7 +227,7 @@ private File generateKeystore(String alias, String password) throws Exception {
return null;
}
}
-
+
return where;
}
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/ModuleDependenciesTest.java b/nbbuild/test/unit/src/org/netbeans/nbbuild/ModuleDependenciesTest.java
index 0d29aa765485..5e00945e56ca 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/ModuleDependenciesTest.java
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/ModuleDependenciesTest.java
@@ -28,6 +28,8 @@
import java.util.jar.Manifest;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Rule;
/** Check the behaviour ModuleDependencies task that prints out info about
* module dependencies, etc.
@@ -35,6 +37,17 @@
* @author Jaroslav Tulach
*/
public class ModuleDependenciesTest extends TestBase {
+
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ System.clearProperty("limit");
+ }
+
+
public ModuleDependenciesTest (String name) {
super (name);
}
@@ -60,14 +73,14 @@ public void testJustMakeSureWeAreAbleToParseTheStructure () throws Exception {
);
execute (f, new String[] { });
}*/
-
+
public void testPublicPackagesOfAModuleThatDoesNotDefineThem () throws Exception {
File notAModule = generateJar (new String[] { "not/X.class", "not/resource/X.html" }, createManifest ());
-
+
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
File withoutPkgs = generateJar (new String[] { "DefaultPkg.class", "is/X.class", "is/too/MyClass.class", "not/as/it/is/resource/X.xml" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "is.there.*, is.recursive.**");
@@ -77,13 +90,13 @@ public void testPublicPackagesOfAModuleThatDoesNotDefineThem () throws Exception
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.very.public.module/10");
m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "-");
File allPkgs = generateJar (new String[] { "not/very/A.class", "not/very/B.class", "not/very/sub/Root.class", "not/res/X.jpg"}, m);
-
+
File parent = notAModule.getParentFile ();
assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
assertEquals ("All parents are the same 3", parent, allPkgs.getParentFile ());
-
-
+
+
File output = extractString ("");
output.delete ();
assertFalse ("Is gone", output.exists ());
@@ -106,12 +119,13 @@ public void testPublicPackagesOfAModuleThatDoesNotDefineThem () throws Exception
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
-
+
assertEquals ("No not package", -1, res.indexOf ("not"));
assertTrue ("Some of is pkgs: " + res, res.indexOf ("is\n") >= 0);
assertEquals ("No default pkg", -1, res.indexOf ("\n\n"));
@@ -121,12 +135,12 @@ public void testPublicPackagesOfAModuleThatDoesNotDefineThem () throws Exception
public void testPublicPackagesInAModuleThatDeclaresFriendsAreNotCounted() throws Exception {
File notAModule = generateJar (new String[] { "not/X.class", "not/resource/X.html" }, createManifest ());
-
+
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Friends", "my.very.public.module");
File withoutPkgs = generateJar (new String[] { "DefaultPkg.class", "just/friend/X.class", "just/friend/MyClass.class", "not/as/it/is/resource/X.xml" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "friend.there.*, friend.recursive.**");
@@ -137,13 +151,13 @@ public void testPublicPackagesInAModuleThatDeclaresFriendsAreNotCounted() throws
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.very.public.module/10");
m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "-");
File allPkgs = generateJar (new String[] { "not/very/A.class", "not/very/B.class", "not/very/sub/Root.class", "not/res/X.jpg"}, m);
-
+
File parent = notAModule.getParentFile ();
assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
assertEquals ("All parents are the same 3", parent, allPkgs.getParentFile ());
-
-
+
+
File output = extractString ("");
output.delete ();
File friendPkg = extractString ("");
@@ -169,24 +183,25 @@ public void testPublicPackagesInAModuleThatDeclaresFriendsAreNotCounted() throws
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
-
+
if (!res.isEmpty()) {
fail("No public packages:\n'" + res + "'");
}
-
+
// now friend packages
res = readFile(friendPkg);
-
+
Matcher match = Pattern.compile("MODULE ([^ ]*)").matcher(res);
assertTrue("One MODULE is there: " + res, match.find());
int fst = match.start();
assertEquals("my.another.module", match.group(1));
-
+
assertTrue("Second MODULE is there: " + res, match.find());
int snd = match.start();
assertEquals("my.module", match.group(1));
@@ -194,19 +209,19 @@ public void testPublicPackagesInAModuleThatDeclaresFriendsAreNotCounted() throws
match = Pattern.compile(" FRIEND my.very.public.module \\(ahoj\\)").matcher(res);
assertTrue("One FRIEND is there: " + res, match.find());
assertTrue("Second FRIEND is there: " + res, match.find());
-
+
assertTrue("FriendPkg1\n" + res, res.indexOf("just.friend") >= snd);
assertTrue("FriendPkg2\n" + res, res.indexOf("friend.there") >= fst);
-
+
}
public void testThereCanBeLimitOnNumberOfFriends() throws Exception {
File notAModule = generateJar (new String[] { "not/X.class", "not/resource/X.html" }, createManifest ());
-
+
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Friends", "my.very.public.module");
File withoutPkgs = generateJar (new String[] { "DefaultPkg.class", "just/friend/X.class", "just/friend/MyClass.class", "not/as/it/is/resource/X.xml" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "friend.there.*, friend.recursive.**");
@@ -217,13 +232,13 @@ public void testThereCanBeLimitOnNumberOfFriends() throws Exception {
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.very.public.module/10");
m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "-");
File allPkgs = generateJar (new String[] { "not/very/A.class", "not/very/B.class", "not/very/sub/Root.class", "not/res/X.jpg"}, m);
-
+
File parent = notAModule.getParentFile ();
assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
assertEquals ("All parents are the same 3", parent, allPkgs.getParentFile ());
-
-
+
+
File output = extractString ("");
output.delete ();
File friendPkg = extractString ("");
@@ -251,17 +266,18 @@ public void testThereCanBeLimitOnNumberOfFriends() throws Exception {
""
);
// this should succeed now, as the limit applies only to intercluster relations - #87076
- execute (f, new String[] { "-verbose" });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
}
public void testThereCanBeLimitOnNumberOfFriendsAmongGroups() throws Exception {
File notAModule = generateJar (new String[] { "not/X.class", "not/resource/X.html" }, createManifest ());
-
+
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Friends", "my.very.public.module");
File myModule = generateJar (new String[] { "DefaultPkg.class", "just/friend/X.class", "just/friend/MyClass.class", "not/as/it/is/resource/X.xml" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "friend.there.*, friend.recursive.**");
@@ -272,13 +288,13 @@ public void testThereCanBeLimitOnNumberOfFriendsAmongGroups() throws Exception {
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.very.public.module/10");
m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "-");
File myVeryPublicModule = generateJar (new String[] { "not/very/A.class", "not/very/B.class", "not/very/sub/Root.class", "not/res/X.jpg"}, m);
-
+
File parent = notAModule.getParentFile ();
assertEquals ("All parents are the same 1", parent, myModule.getParentFile ());
assertEquals ("All parents are the same 2", parent, myAnotherModule.getParentFile ());
assertEquals ("All parents are the same 3", parent, myVeryPublicModule.getParentFile ());
-
-
+
+
File friendPkg = extractString ("");
friendPkg.delete ();
assertFalse ("Is gone", friendPkg.exists ());
@@ -307,8 +323,9 @@ public void testThereCanBeLimitOnNumberOfFriendsAmongGroups() throws Exception {
""
);
- execute (f, new String[] { "-verbose", "-Dlimit=1" });
-
+ System.setProperty("limit", "1");
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
String res = readFile (friendPkg);
assertEquals(
@@ -321,15 +338,15 @@ public void testThereCanBeLimitOnNumberOfFriendsAmongGroups() throws Exception {
" PACKAGE friend.there\n" +
"", res);
}
-
+
public void testThereExternalsAreCountedAsWell() throws Exception {
File notAModule = generateJar (new String[] { "not/X.class", "not/resource/X.html" }, createManifest ());
-
+
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Friends", "my.very.public.module");
File myModule = generateJar (new String[] { "DefaultPkg.class", "just/friend/X.class", "just/friend/MyClass.class", "not/as/it/is/resource/X.xml" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "friend.there.*, friend.recursive.**");
@@ -340,13 +357,13 @@ public void testThereExternalsAreCountedAsWell() throws Exception {
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.very.public.module/10");
m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "-");
File myVeryPublicModule = generateJar (new String[] { "not/very/A.class", "not/very/B.class", "not/very/sub/Root.class", "not/res/X.jpg"}, m);
-
+
File parent = notAModule.getParentFile ();
assertEquals ("All parents are the same 1", parent, myModule.getParentFile ());
assertEquals ("All parents are the same 2", parent, myAnotherModule.getParentFile ());
assertEquals ("All parents are the same 3", parent, myVeryPublicModule.getParentFile ());
-
-
+
+
File friendPkg = extractString ("");
friendPkg.delete ();
assertFalse ("Is gone", friendPkg.exists ());
@@ -369,8 +386,10 @@ public void testThereExternalsAreCountedAsWell() throws Exception {
""
);
- execute (f, new String[] { "-verbose", "-Dlimit=1" });
-
+ System.setProperty("limit", "1");
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
String res = readFile (friendPkg);
assertEquals(
@@ -383,19 +402,19 @@ public void testThereExternalsAreCountedAsWell() throws Exception {
" PACKAGE friend.there\n" +
"", res);
}
-
+
public void testPublicPackagesOfAModuleThatDoesNotDefineThemButTheyAreProvidedByModuleTheModuleDependsOn () throws Exception {
File notAModule = generateJar (new String[] { "is/cp/X.class", "not/cp/resource/X.html" }, createManifest ());
-
+
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
m.getMainAttributes ().putValue ("Class-Path", notAModule.getName ());
File withoutPkgs = generateJar (new String[] { "DefaultPkg.class", "is/X.class", "is/too/MyClass.class", "not/as/it/is/resource/X.xml" }, m);
-
+
File parent = notAModule.getParentFile ();
assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
-
-
+
+
File output = extractString ("");
output.delete ();
assertFalse ("Is gone", output.exists ());
@@ -416,32 +435,33 @@ public void testPublicPackagesOfAModuleThatDoesNotDefineThemButTheyAreProvidedBy
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
-
+
assertEquals ("No not package", -1, res.indexOf ("not"));
assertTrue ("Some of is pkgs: " + res, res.indexOf ("is\n") >= 0);
assertTrue ("is/too pkgs: " + res, res.indexOf ("is.too\n") >= 0);
assertEquals ("No default pkg", -1, res.indexOf ("\n\n"));
assertTrue ("is/cp is there as well as the withoutPkgs module depends on notAModule: " + res, res.indexOf ("is.cp\n") >= 0);
}
-
+
public void testPublicPackagesForOneCluster() throws Exception {
Manifest m1 = createManifest ();
m1.getMainAttributes ().putValue ("OpenIDE-Module", "my.ignored.module/3");
File ignoreModule = generateJar (new String[] { "DefaultPkg.class", "is2/X.class", "is2/too/MyClass.class", "not/as/it/is/resource/X.xml" }, m1);
-
+
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
File withoutPkgs = generateJar (new String[] { "DefaultPkg.class", "is/X.class", "is/too/MyClass.class", "not/as/it/is/resource/X.xml" }, m);
-
+
File parent = ignoreModule.getParentFile ();
assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
-
-
+
+
File output = extractString ("");
output.delete ();
assertFalse ("Is gone", output.exists ());
@@ -466,12 +486,13 @@ public void testPublicPackagesForOneCluster() throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
-
+
assertEquals ("No not package", -1, res.indexOf ("not"));
assertEquals ("No is2 package", -1, res.indexOf ("is2"));
assertTrue ("Some of is pkgs: " + res, res.indexOf ("is\n") >= 0);
@@ -483,20 +504,20 @@ public void testSharedPackagesForOneCluster() throws Exception {
Manifest m0 = createManifest ();
m0.getMainAttributes ().putValue ("OpenIDE-Module", "my.huge.module/3");
File hugeModule = generateJar (new String[] { "not/X.class", "is/too/MyClass.class", }, m0);
-
-
+
+
Manifest m1 = createManifest ();
m1.getMainAttributes ().putValue ("OpenIDE-Module", "my.ignored.module/3");
File ignoreModule = generateJar (new String[] { "not/X.class" }, m1);
-
+
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
File withoutPkgs = generateJar (new String[] { "is/too/MyClass.class" }, m);
-
+
File parent = ignoreModule.getParentFile ();
assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
-
-
+
+
File output = extractString ("");
output.delete ();
assertFalse ("Is gone", output.exists ());
@@ -522,25 +543,26 @@ public void testSharedPackagesForOneCluster() throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
-
+
assertEquals ("No not package:\n" + res, -1, res.indexOf ("not"));
assertTrue ("is/too pkgs: " + res, res.indexOf ("is.too\n") >= 0);
assertEquals ("No default pkg:\n" + res, -1, res.indexOf ("\n\n"));
}
-
+
public void testNameOfModuleWithoutMajorVersionDoesNotContainSlash () throws Exception {
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module");
File module = generateJar (new String[] { "something" }, m);
-
+
File parent = module.getParentFile ();
-
-
+
+
File output = extractString ("");
output.delete ();
assertFalse ("Is gone", output.exists ());
@@ -560,35 +582,36 @@ public void testNameOfModuleWithoutMajorVersionDoesNotContainSlash () throws Exc
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
assertEquals ("Starts with MODULE", 0, res.indexOf ("MODULE"));
assertTrue ("module name is there" + res, res.indexOf ("my.module") > 0);
assertEquals ("no slash is there", -1, res.indexOf ('/'));
}
-
-
+
+
public void testGenerateListOfModules () throws Exception {
File notAModule = generateJar (new String[] { "not/X.class", "not/resource/X.html" }, createManifest ());
-
+
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
File withoutPkgs = generateJar (new String[] { "DefaultPkg.class", "is/X.class", "is/too/MyClass.class", "not/as/it/is/resource/X.xml" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "is.there.*, is.recursive.**");
File withPkgs = generateJar (new String[] { "is/there/A.class", "not/there/B.class", "is/recursive/Root.class", "is/recursive/sub/Under.class", "not/res/X.jpg"}, m);
-
+
File parent = notAModule.getParentFile ();
assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
-
-
+
+
File output = extractString ("");
output.delete ();
assertFalse ("Is gone", output.exists ());
@@ -610,36 +633,37 @@ public void testGenerateListOfModules () throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
StringTokenizer tok = new StringTokenizer (res, "\n\r");
-
+
assertEquals ("We have two modules: " + res, 2, tok.countTokens ());
assertEquals ("First contains another module, as it is sooner in alphabet\n" + res, "MODULE my.another.module/3 (ahoj)", tok.nextToken ());
assertEquals ("Second the next one" + res, "MODULE my.module/3 (ahoj)", tok.nextToken ());
assertFalse ("No next tokens", tok.hasMoreElements ());
}
-
+
public void testGenerateListOfForOneCluster () throws Exception {
File notAModule = generateJar (new String[] { "not/X.class", "not/resource/X.html" }, createManifest ());
-
+
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
File withoutPkgs = generateJar (new String[] { "DefaultPkg.class", "is/X.class", "is/too/MyClass.class", "not/as/it/is/resource/X.xml" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "is.there.*, is.recursive.**");
File withPkgs = generateJar (new String[] { "is/there/A.class", "not/there/B.class", "is/recursive/Root.class", "is/recursive/sub/Under.class", "not/res/X.jpg"}, m);
-
+
File parent = notAModule.getParentFile ();
assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
-
-
+
+
File output = extractString ("");
output.delete ();
assertFalse ("Is gone", output.exists ());
@@ -665,35 +689,36 @@ public void testGenerateListOfForOneCluster () throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
StringTokenizer tok = new StringTokenizer(res, "\n\r");
assertEquals("Should be empty:\n" + res, 0, tok.countTokens());
}
-
+
public void testGenerateModuleDependencies () throws Exception {
Manifest openideManifest = createManifest ();
openideManifest.getMainAttributes ().putValue ("OpenIDE-Module", "org.openide/1");
File openide = generateJar (new String[] { "notneeded" }, openideManifest);
-
+
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "org.openide/1 > 4.17");
File withoutPkgs = generateJar (new String[] { "notneeded" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "my.module/3, org.openide/1 > 4.17");
File withPkgs = generateJar (new String[] { "some content"}, m);
-
+
File parent = openide.getParentFile ();
assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
-
-
+
+
File output = extractString ("");
output.delete ();
assertFalse ("Is gone", output.exists ());
@@ -719,10 +744,11 @@ public void testGenerateModuleDependencies () throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
int y = res.indexOf ("MODULE", 1);
if (y <= 0) {
@@ -733,13 +759,13 @@ public void testGenerateModuleDependencies () throws Exception {
// f1 is later due to algebraic sorting of modules!!!!
StringTokenizer f2 = new StringTokenizer (res.substring (0, y), "\r\n");
StringTokenizer f1 = new StringTokenizer (res.substring (y), "\r\n");
-
+
assertEquals ("One line + one dep for f1\n" + res, 2, f1.countTokens ());
f1.nextToken ();
String dep1 = f1.nextToken ();
assertTrue (dep1, dep1.startsWith (" REQUIRES"));
assertTrue ("on " + dep1, dep1.indexOf ("org.openide") >= 0);
-
+
assertEquals ("One line + two dep for f2", 3, f2.countTokens ());
f2.nextToken ();
String dep2 = f2.nextToken ();
@@ -748,29 +774,29 @@ public void testGenerateModuleDependencies () throws Exception {
dep2 = f2.nextToken ();
assertTrue (dep2, dep2.startsWith (" REQUIRES"));
assertTrue ("on " + dep2, dep2.indexOf ("org.openide") >= 0);
-
+
}
-
+
public void testGenerateModuleDependenciesInOneClusterOnly() throws Exception {
Manifest openideManifest = createManifest ();
openideManifest.getMainAttributes ().putValue ("OpenIDE-Module", "org.openide/1");
File openide = generateJar (new String[] { "notneeded" }, openideManifest);
-
+
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "org.openide/1 > 4.17");
File withoutPkgs = generateJar (new String[] { "notneeded" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "my.module/3, org.openide/1 > 4.17");
File withPkgs = generateJar (new String[] { "some content"}, m);
-
+
File parent = openide.getParentFile ();
assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
-
-
+
+
File output = extractString ("");
output.delete ();
assertFalse ("Is gone", output.exists ());
@@ -796,10 +822,11 @@ public void testGenerateModuleDependenciesInOneClusterOnly() throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
int y = res.indexOf ("MODULE");
if (y < 0) {
@@ -808,7 +835,7 @@ public void testGenerateModuleDependenciesInOneClusterOnly() throws Exception {
assertEquals ("No other", -1, res.indexOf ("MODULE", y + 1));
StringTokenizer f2 = new StringTokenizer (res, "\r\n");
-
+
assertEquals ("One line + two dep for f2", 3, f2.countTokens ());
f2.nextToken ();
String dep2 = f2.nextToken ();
@@ -817,29 +844,29 @@ public void testGenerateModuleDependenciesInOneClusterOnly() throws Exception {
dep2 = f2.nextToken ();
assertTrue (dep2, dep2.startsWith (" REQUIRES"));
assertTrue ("on " + dep2, dep2.indexOf ("org.openide") >= 0);
-
+
}
public void testImplementationModuleDependenciesAreRegularDepsAsWell () throws Exception {
Manifest openideManifest = createManifest ();
openideManifest.getMainAttributes ().putValue ("OpenIDE-Module", "org.openide/1");
File openide = generateJar (new String[] { "notneeded" }, openideManifest);
-
+
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "org.openide/1 > 4.17");
File withoutPkgs = generateJar (new String[] { "notneeded" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "my.module/3 = Ahoj, org.openide/1 > 4.17");
File withPkgs = generateJar (new String[] { "some content"}, m);
-
+
File parent = openide.getParentFile ();
assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
-
-
+
+
File output = extractString ("");
output.delete ();
assertFalse ("Is gone", output.exists ());
@@ -865,10 +892,11 @@ public void testImplementationModuleDependenciesAreRegularDepsAsWell () throws E
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
int x = res.indexOf ("MODULE");
assertEquals ("The file starts with MODULE", 0, x);
@@ -881,13 +909,13 @@ public void testImplementationModuleDependenciesAreRegularDepsAsWell () throws E
// f1 is later due to algebraic sorting of modules!!!!
StringTokenizer f2 = new StringTokenizer (res.substring (0, y), "\r\n");
StringTokenizer f1 = new StringTokenizer (res.substring (y), "\r\n");
-
+
assertEquals ("One line + one dep for f1\n" + res, 2, f1.countTokens ());
f1.nextToken ();
String dep1 = f1.nextToken ();
assertTrue (dep1, dep1.startsWith (" REQUIRES"));
assertTrue ("on " + dep1, dep1.indexOf ("org.openide") >= 0);
-
+
assertEquals ("One line + two dep for f2", 3, f2.countTokens ());
f2.nextToken ();
String dep2 = f2.nextToken ();
@@ -896,24 +924,24 @@ public void testImplementationModuleDependenciesAreRegularDepsAsWell () throws E
dep2 = f2.nextToken ();
assertTrue (dep2, dep2.startsWith (" REQUIRES"));
assertTrue ("on " + dep2, dep2.indexOf ("org.openide") >= 0);
-
+
}
public void testGenerateImplementationModuleDependencies () throws Exception {
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
File withoutPkgs = generateJar (new String[] { "notneeded" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "my.module/3 = Ahoj");
File withPkgs = generateJar (new String[] { "some content"}, m);
-
+
File parent = withoutPkgs.getParentFile ();
assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
-
-
+
+
File output = extractString ("");
output.delete ();
assertFalse ("Is gone", output.exists ());
@@ -934,10 +962,11 @@ public void testGenerateImplementationModuleDependencies () throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
int x = res.indexOf ("MODULE");
assertEquals ("The file starts with MODULE", 0, x);
@@ -945,7 +974,7 @@ public void testGenerateImplementationModuleDependencies () throws Exception {
assertEquals ("No other:\n" + res, -1, y);
StringTokenizer f1 = new StringTokenizer (res, "\r\n");
-
+
assertEquals ("One line + one dep for f1\n" + res, 2, f1.countTokens ());
String modulename = f1.nextToken ();
assertTrue ("module is ", modulename.indexOf ("my.another.module") >= 0);
@@ -953,28 +982,28 @@ public void testGenerateImplementationModuleDependencies () throws Exception {
assertTrue (dep1, dep1.startsWith (" REQUIRES"));
assertTrue ("on " + dep1, dep1.indexOf ("my.module") >= 0);
}
-
-
+
+
public void testCanOutputJustDependenciesBetweenClusters () throws Exception {
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "org.openidex/1");
File openide = generateJar (new String[] { "notneeded" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "org.openidex/1");
File withoutPkgs = generateJar (new String[] { "notneeded" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "my.module/3 = Ahoj, org.openidex/1");
File withPkgs = generateJar (new String[] { "some content"}, m);
-
+
File parent = withoutPkgs.getParentFile ();
assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
-
-
+
+
File output = extractString ("");
output.delete ();
assertFalse ("Is gone", output.exists ());
@@ -1000,10 +1029,11 @@ public void testCanOutputJustDependenciesBetweenClusters () throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
int x = res.indexOf ("GROUP");
assertEquals ("The file starts with GROUP", 0, x);
@@ -1011,7 +1041,7 @@ public void testCanOutputJustDependenciesBetweenClusters () throws Exception {
assertEquals ("No other:\n" + res, -1, y);
StringTokenizer f1 = new StringTokenizer (res, "\r\n");
-
+
assertEquals ("One line + dep on openide\n" + res, 2, f1.countTokens ());
String groupname = f1.nextToken ();
assertTrue ("group is " + res, groupname.indexOf ("others") >= 0);
@@ -1019,27 +1049,27 @@ public void testCanOutputJustDependenciesBetweenClusters () throws Exception {
assertTrue (dep1, dep1.startsWith (" REQUIRES"));
assertTrue ("on openide module" + dep1, dep1.indexOf ("org.openide") >= 0);
}
-
+
public void testCanOutputJustDependenciesBetweenClustersForOneCluster() throws Exception {
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "org.openidex/1");
File openide = generateJar (new String[] { "notneeded" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "org.openidex/1");
File withoutPkgs = generateJar (new String[] { "notneeded" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "my.module/3 = Ahoj, org.openidex/1");
File withPkgs = generateJar (new String[] { "some content"}, m);
-
+
File parent = withoutPkgs.getParentFile ();
assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
-
-
+
+
File output = extractString ("");
output.delete ();
assertFalse ("Is gone", output.exists ());
@@ -1069,10 +1099,11 @@ public void testCanOutputJustDependenciesBetweenClustersForOneCluster() throws E
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
int x = res.indexOf ("GROUP");
assertEquals ("The file starts with GROUP", 0, x);
@@ -1080,7 +1111,7 @@ public void testCanOutputJustDependenciesBetweenClustersForOneCluster() throws E
assertEquals ("No other:\n" + res, -1, y);
StringTokenizer f1 = new StringTokenizer (res, "\r\n");
-
+
assertEquals ("One line + dep on openide and the other module\n" + res, 3, f1.countTokens ());
String groupname = f1.nextToken ();
assertTrue ("group is " + res, groupname.indexOf ("others") >= 0);
@@ -1091,22 +1122,22 @@ public void testCanOutputJustDependenciesBetweenClustersForOneCluster() throws E
assertTrue (dep2, dep2.startsWith (" REQUIRES"));
assertTrue ("on openide module" + dep2, dep2.indexOf ("org.openide") >= 0);
}
-
+
public void testCanOutputJustImplDependenciesBetweenClusters () throws Exception {
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "org.openidex/1");
File openide = generateJar (new String[] { "notneeded" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "org.netbeans.core/1");
File core = generateJar (new String[] { "notneeded" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "org.openidex/1");
File withoutPkgs = generateJar (new String[] { "notneeded" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "my.module/3 = Ahoj, org.openidex/1");
@@ -1116,13 +1147,13 @@ public void testCanOutputJustImplDependenciesBetweenClusters () throws Exception
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module.dependingoncore/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "org.netbeans.core/1 = Ahoj, my.module/3 > 4.17");
File coredepender = generateJar (new String[] { "notneeded" }, m);
-
-
+
+
File parent = withoutPkgs.getParentFile ();
assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
-
-
+
+
File output = extractString ("");
output.delete ();
assertFalse ("Is gone", output.exists ());
@@ -1154,10 +1185,11 @@ public void testCanOutputJustImplDependenciesBetweenClusters () throws Exception
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
int x = res.indexOf ("GROUP");
assertEquals ("The file starts with GROUP", 0, x);
@@ -1165,7 +1197,7 @@ public void testCanOutputJustImplDependenciesBetweenClusters () throws Exception
assertEquals ("No other:\n" + res, -1, y);
StringTokenizer f1 = new StringTokenizer (res, "\r\n");
-
+
assertEquals ("One line + dep on openide\n" + res, 2, f1.countTokens ());
String groupname = f1.nextToken ();
assertTrue ("group is " + res, groupname.indexOf ("rest") >= 0);
@@ -1173,23 +1205,23 @@ public void testCanOutputJustImplDependenciesBetweenClusters () throws Exception
assertTrue (dep1, dep1.startsWith (" REQUIRES"));
assertTrue ("on openide module" + dep1, dep1.indexOf ("org.netbeans.core") >= 0);
}
-
+
public void testRangeDependencyNeedsToBeParsed () throws Exception {
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "org.openidex/1");
File withoutPkgs = generateJar (new String[] { "notneeded" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "my.module/2-3 = Ahoj, org.openidex/1-2 > 4.17");
File withPkgs = generateJar (new String[] { "some content"}, m);
-
+
File parent = withoutPkgs.getParentFile ();
assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
-
-
+
+
File output = extractString ("");
output.delete ();
assertFalse ("Is gone", output.exists ());
@@ -1210,10 +1242,11 @@ public void testRangeDependencyNeedsToBeParsed () throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
int x = res.indexOf ("MODULE");
assertEquals ("The file starts with MODULE", 0, x);
@@ -1221,7 +1254,7 @@ public void testRangeDependencyNeedsToBeParsed () throws Exception {
assertEquals ("No other:\n" + res, -1, y);
StringTokenizer f1 = new StringTokenizer (res, "\r\n");
-
+
assertEquals ("One line + one dep for f1\n" + res, 2, f1.countTokens ());
String modulename = f1.nextToken ();
assertTrue ("module is ", modulename.indexOf ("my.another.module") >= 0);
@@ -1235,17 +1268,17 @@ public void testGenerateProvidesRequiresDependencies () throws Exception {
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Provides", "my.token");
File withoutPkgs = generateJar (new String[] { "notneeded" }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/7");
m.getMainAttributes ().putValue ("OpenIDE-Module-Requires", "my.token");
File withPkgs = generateJar (new String[] { "some content"}, m);
-
+
File parent = withoutPkgs.getParentFile ();
assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
-
-
+
+
File output = extractString ("");
output.delete ();
assertFalse ("Is gone", output.exists ());
@@ -1266,10 +1299,11 @@ public void testGenerateProvidesRequiresDependencies () throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
int x = res.indexOf ("MODULE");
assertEquals ("The file starts with MODULE", 0, x);
@@ -1277,7 +1311,7 @@ public void testGenerateProvidesRequiresDependencies () throws Exception {
assertEquals ("No other module: " + res, -1, y);
StringTokenizer f1 = new StringTokenizer (res, "\r\n");
-
+
assertEquals ("One line + one dep for f1\n" + res, 2, f1.countTokens ());
String modulename = f1.nextToken ();
assertTrue ("module name contains another " + modulename, modulename.indexOf ("my.another.module") > 0);
@@ -1291,10 +1325,10 @@ public void testSpecialDependenciesArePrintedWithoutSearchingForAppropriateModul
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
m.getMainAttributes ().putValue ("OpenIDE-Module-Requires", "org.openide.modules.os.MacOSX");
File withPkgs = generateJar (new String[] { "some content"}, m);
-
+
File parent = withPkgs.getParentFile ();
-
-
+
+
File output = extractString ("");
File output2 = extractString ("");
output.delete ();
@@ -1316,43 +1350,44 @@ public void testSpecialDependenciesArePrintedWithoutSearchingForAppropriateModul
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
int x = res.indexOf ("MODULE");
assertEquals ("The file starts with MODULE:" + res, 0, x);
assertEquals ("No other", -1, res.indexOf ("MODULE", x + 1));
StringTokenizer f1 = new StringTokenizer (res, "\r\n");
-
+
assertEquals ("One line + one dep for f1\n" + res, 2, f1.countTokens ());
String modname = f1.nextToken ();
assertTrue ("Name: " + modname, modname.indexOf ("my.another.module") > 0);
String dep1 = f1.nextToken ();
assertTrue (dep1, dep1.startsWith (" REQUIRES"));
assertTrue ("on " + dep1, dep1.indexOf ("org.openide.modules.os.MacOSX") >= 0);
-
+
}
-
+
public void testPrintNamesOfPackagesSharedBetweenMoreModules() throws Exception {
File notAModule = generateJar (new String[] { "org/shared/not/X.class", "org/shared/yes/X.html" }, createManifest ());
-
+
Manifest m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
File withoutPkgs = generateJar (new String[] { "org/shared/yes/Bla.class", "org/shared/not/sub/MyClass.class", }, m);
-
+
m = createManifest ();
m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
m.getMainAttributes ().putValue ("Class-Path", notAModule.getName ());
File withPkgs = generateJar (new String[] { "org/shared/not/res/X.jpg"}, m);
-
+
File parent = notAModule.getParentFile ();
assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
-
-
+
+
File output = extractString ("");
output.delete ();
assertFalse ("Is gone", output.exists ());
@@ -1374,12 +1409,13 @@ public void testPrintNamesOfPackagesSharedBetweenMoreModules() throws Exception
"" +
""
);
- execute (f, new String[] { "-verbose" });
-
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
+
assertTrue ("Result generated", output.exists ());
-
+
String res = readFile (output);
-
+
assertEquals("No not package: '" + res + "'", -1, res.indexOf("org.shared.not"));
assertEquals ("No default pkg", -1, res.indexOf ("\n\n"));
assertEquals ("No ork pkg", -1, res.indexOf ("org\n"));
@@ -1397,10 +1433,10 @@ private File createNewJarFile() throws IOException {
}
}
}
-
+
private File generateJar(String[] content, Manifest manifest) throws IOException {
File f = createNewJarFile ();
-
+
try (JarOutputStream os = new JarOutputStream (new FileOutputStream (f), manifest)) {
for (int i = 0; i < content.length; i++) {
os.putNextEntry(new JarEntry (content[i]));
@@ -1408,8 +1444,8 @@ private File generateJar(String[] content, Manifest manifest) throws IOException
}
os.closeEntry ();
}
-
+
return f;
}
-
+
}
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/PathFileSetTest.java b/nbbuild/test/unit/src/org/netbeans/nbbuild/PathFileSetTest.java
index 310c706ec8f0..bfef7c2ece6d 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/PathFileSetTest.java
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/PathFileSetTest.java
@@ -21,16 +21,14 @@
import java.io.File;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
-import java.util.StringTokenizer;
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildListener;
-import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.resources.FileResource;
import org.apache.tools.ant.types.selectors.FilenameSelector;
import org.junit.AfterClass;
@@ -109,7 +107,7 @@ protected void tearDown() {
private void executeAndCheckResults(String[] expected) throws BuildException, IOException {
String[] output = new String[pfs.size()];
int j = 0;
- for (Iterator it = pfs.iterator(); it.hasNext(); j++) {
+ for (Iterator it = pfs.iterator(); it.hasNext(); j++) {
FileResource fileResource = (FileResource) it.next();
String path = fileResource.getFile().getAbsolutePath().replace('\\', '/');
output[j] = path;
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/PrintIconTest.java b/nbbuild/test/unit/src/org/netbeans/nbbuild/PrintIconTest.java
index cdef3853e7a0..68b28451a127 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/PrintIconTest.java
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/PrintIconTest.java
@@ -24,6 +24,8 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Rule;
/**
* @author Jaroslav Tulach
@@ -33,7 +35,9 @@ public class PrintIconTest extends TestBase {
public PrintIconTest(String testName) {
super(testName);
}
-
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
+
// For some reason, TestBase.extractResource does not work in this test:
private File extractCountedResource(String resource) throws Exception {
File f;
@@ -77,7 +81,8 @@ public void testPrintOutSameIcons() throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertTrue("Exists: " + out, out.canRead());
@@ -125,7 +130,8 @@ public void testDuplicatesFromTheSameSet() throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertTrue("Exists: " + out, out.canRead());
@@ -179,7 +185,8 @@ private void doBrokenImageTest(String res) throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertTrue("Exists: " + out, out.canRead());
@@ -228,7 +235,8 @@ public void testPrintExtra() throws Exception {
"" +
""
);
- execute (f, new String[] { "-verbose" });
+ buildRule.configureProject(f.getAbsolutePath());
+ buildRule.executeTarget("all");
assertTrue("Exists: " + out, out.canRead());
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/PublicPackagesInProjectizedXMLTest.java b/nbbuild/test/unit/src/org/netbeans/nbbuild/PublicPackagesInProjectizedXMLTest.java
index 94e406863ddd..a36b929d28ed 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/PublicPackagesInProjectizedXMLTest.java
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/PublicPackagesInProjectizedXMLTest.java
@@ -19,11 +19,19 @@
package org.netbeans.nbbuild;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Rule;
+
/** Check the behaviour of in project.xml modules.
*
* @author Jaroslav Tulach
*/
public class PublicPackagesInProjectizedXMLTest extends TestBase {
+
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
+
public PublicPackagesInProjectizedXMLTest (String name) {
super (name);
}
@@ -43,9 +51,12 @@ public void testPackageCannotContainComma () throws Exception {
""
);
try {
- execute ("GarbageUnderPackages.xml", new String[] { "-Dproject.file=" + f });
+ System.setProperty("project.file", f.getAbsolutePath());
+ buildRule.configureProject(getBuildFileInClassPath("GarbageUnderPackages.xml"));
+ buildRule.executeTarget("all");
+
fail ("This should fail as the public package definition contains comma");
- } catch (ExecutionError ex) {
+ } catch (BuildException ex) {
// ok, this should fail on exit code
}
}
@@ -65,9 +76,11 @@ public void testPackageCannotContainStar () throws Exception {
""
);
try {
- execute ("GarbageUnderPackages.xml", new String[] { "-Dproject.file=" + f });
+ System.setProperty("project.file", f.getAbsolutePath());
+ buildRule.configureProject(getBuildFileInClassPath("GarbageUnderPackages.xml"));
+ buildRule.executeTarget("all");
fail ("This should fail as the public package definition contains *");
- } catch (ExecutionError ex) {
+ } catch (BuildException ex) {
// ok, this should fail on exit code
}
}
@@ -87,9 +100,11 @@ public void testPublicPackagesCannotContainGarbageSubelements () throws Exceptio
""
);
try {
- execute ("GarbageUnderPackages.xml", new String[] { "-Dproject.file=" + f });
+ System.setProperty("project.file", f.getAbsolutePath());
+ buildRule.configureProject(getBuildFileInClassPath("GarbageUnderPackages.xml"));
+ buildRule.executeTarget("all");
fail ("This should fail as the public package definition contains *");
- } catch (ExecutionError ex) {
+ } catch (BuildException ex) {
// ok, this should fail on exit code
}
}
@@ -108,7 +123,10 @@ public void testItIsPossibleToDefineSubpackages () throws Exception {
" " +
""
);
- execute ("GarbageUnderPackages.xml", new String[] { "-Dproject.file=" + f, "-Dexpected.public.packages=org.hello.**" });
+ System.setProperty("project.file", f.getAbsolutePath());
+ System.setProperty("expected.public.packages", "org.hello.**");
+ buildRule.configureProject(getBuildFileInClassPath("GarbageUnderPackages.xml"));
+ buildRule.executeTarget("all");
}
/* DISABLED because of fix for #52135:
@@ -149,7 +167,11 @@ public void testSubpackagesDoNotWorkForJavadocNowButThisWorksWhenSpecifiedByHand
" " +
""
);
- execute ("GarbageUnderPackages.xml", new String[] { "-Djavadoc.pac=some", "-Dproject.file=" + f, "withjavadoc" });
+ System.setProperty("project.file", f.getAbsolutePath());
+ System.setProperty("javadoc.pac", "some");
+ buildRule.configureProject(getBuildFileInClassPath("GarbageUnderPackages.xml"));
+ buildRule.executeTarget("withjavadoc");
+
}
}
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/RecursiveDeps.xml b/nbbuild/test/unit/src/org/netbeans/nbbuild/RecursiveDeps.xml
index ac15fa3fb93b..21d0fd35adf4 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/RecursiveDeps.xml
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/RecursiveDeps.xml
@@ -20,7 +20,7 @@
-->
-
+
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/RecursiveDepsTest.java b/nbbuild/test/unit/src/org/netbeans/nbbuild/RecursiveDepsTest.java
index 414c02ef8a66..ca278ceafe5d 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/RecursiveDepsTest.java
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/RecursiveDepsTest.java
@@ -23,13 +23,18 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.Project;
+import org.junit.Rule;
/**
*
* @author pzajac
*/
public class RecursiveDepsTest extends TestBase {
-
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
+
public RecursiveDepsTest(java.lang.String testName) {
super(testName);
}
@@ -43,7 +48,10 @@ protected void setUp() throws Exception {
public void testDepsTest () throws Exception {
// create test
File projectxml = extractFile(RecursiveDepsTest.class.getResourceAsStream("RecursiveDepsProject.xml"),"project.xml");
- execute ("RecursiveDeps.xml", new String[] { "-verbose", "-Dproject.file=" + projectxml, "recursive-deps" });
+ System.setProperty("project.file", projectxml.getAbsolutePath());
+ buildRule.configureProject(getBuildFileInClassPath("RecursiveDeps.xml"),Project.MSG_VERBOSE);
+ buildRule.executeTarget("recursive-deps");
+
}
private File extractFile(InputStream is, String fileName) throws IOException {
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/ShorterPathsTest.java b/nbbuild/test/unit/src/org/netbeans/nbbuild/ShorterPathsTest.java
index bd0670dbc346..c3ac0541cd05 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/ShorterPathsTest.java
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/ShorterPathsTest.java
@@ -29,13 +29,17 @@
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Rule;
/**
*
* @author pzajac
*/
public class ShorterPathsTest extends TestBase {
-
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
+
public ShorterPathsTest(java.lang.String testName) {
super(testName);
}
@@ -57,14 +61,12 @@ public void testShorterPaths() throws Exception {
}
- execute("ShorterPathsTest.xml", new String[]{
- "-verbose",
- "-Dtest.ext.lib=" + extlib.getPath(),
- "-Dtest.modules.dir=" + modules.getPath(),
- "-Dextra.test.libs.dir=" + extraLibsDir.getPath(),
- "-Dtest.properties=" + testProperties.getPath(),
- "all"
- });
+ System.setProperty("test.ext.lib", extlib.getAbsolutePath());
+ System.setProperty("test.modules.dir", modules.getAbsolutePath());
+ System.setProperty("extra.test.libs.dir", extraLibsDir.getAbsolutePath());
+ System.setProperty("test.properties", testProperties.getAbsolutePath());
+ buildRule.configureProject(getBuildFileInClassPath("ShorterPathsTest.xml"));
+ buildRule.executeTarget("all");
File extralibCopy = new File(extraLibsDir, "extlib.jar");
assertTrue("No extra library has been copied", extralibCopy.exists());
@@ -112,14 +114,12 @@ public void testClassPathExtensions() throws Exception {
File extlib = new File(getWorkDir(), "extlib.jar");
generateJar(extlib, new String[]{"a/b/c/Class1.class", "a/b/c/Class2.class"}, m);
- execute("ShorterPathsTest.xml", new String[]{
- "-verbose",
- "-Dtest.ext.lib=" + extlib.getPath(),
- "-Dtest.modules.dir=" + modules.getPath(),
- "-Dextra.test.libs.dir=" + extraLibsDir.getPath(),
- "-Dtest.properties=" + testProperties.getPath(),
- "all"
- });
+ System.setProperty("test.ext.lib", extlib.getAbsolutePath());
+ System.setProperty("test.modules.dir", modules.getAbsolutePath());
+ System.setProperty("extra.test.libs.dir", extraLibsDir.getAbsolutePath());
+ System.setProperty("test.properties", testProperties.getAbsolutePath());
+ buildRule.configureProject(getBuildFileInClassPath("ShorterPathsTest.xml"));
+ buildRule.executeTarget("all");
File extralibCopy = new File(extraLibsDir, "extlib.jar");
assertTrue("Extra library not copied.", extralibCopy.exists());
File classPathExtensionCopy = new File(extraLibsDir, cpExtensionRelativePath);
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/TestBase.java b/nbbuild/test/unit/src/org/netbeans/nbbuild/TestBase.java
index 9fc0634100a9..18ccad4b9884 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/TestBase.java
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/TestBase.java
@@ -58,7 +58,11 @@ protected final String readFile(java.io.File f) throws java.io.IOException {
return new String(data);
}
-
+ protected final String getBuildFileInClassPath(String filename) {
+ // Hack to find where classes
+ return getDataDir().getAbsolutePath().replace("data", "classes") +
+ File.separator + "org" + File.separator + "netbeans" + File.separator + "nbbuild" + File.separator+ filename;
+ }
protected final Manifest createManifest() {
Manifest m = new Manifest();
m.getMainAttributes().putValue(java.util.jar.Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
@@ -103,196 +107,5 @@ protected final void extractResource(File f, String res) throws Exception {
os.write(ch);
}
}
- }
-
- protected final void execute(String res, String... args) throws Exception {
- execute(extractResource(res), args);
- }
-
- private static ByteArrayOutputStream out, err;
-
- protected final String getStdOut() {
- return out.toString();
- }
-
- protected final String getStdErr() {
- return err.toString();
- }
-
- protected final void execute(File f, String[] args) throws Exception {
- // we need security manager to prevent System.exit
- if (!(System.getSecurityManager() instanceof MySecMan)) {
- out = new java.io.ByteArrayOutputStream();
- err = new java.io.ByteArrayOutputStream();
- System.setOut(new java.io.PrintStream(out));
- System.setErr(new java.io.PrintStream(err));
-
- System.setSecurityManager(new MySecMan());
- }
-
- MySecMan sec = (MySecMan) System.getSecurityManager();
-
- // Jesse claims that this is not the right way how the execution
- // of an ant script should be invoked:
- //
- // better IMHO to just run the task directly
- // (setProject() and similar, configure its bean properties, and call
- // execute()), or just make a new Project and initialize it.
- // ant.Main.main is not intended for embedded use. Then you could get rid
- // of the SecurityManager stuff, would be cleaner I think.
- //
- // If I had to write this once again, I would try to follow the
- // "just make a new Project and initialize it", but as this works
- // for me now, I leave it for the time when somebody really
- // needs that...
-
- List arr = new ArrayList<>();
- arr.add("-f");
- arr.add(f.toString());
- arr.addAll(Arrays.asList(args));
-
-
- out.reset();
- err.reset();
-
- try {
- sec.setActive(true);
- org.apache.tools.ant.Main.main(arr.toArray(new String[0]));
- } catch (MySecExc ex) {
- assertNotNull("The only one to throw security exception is MySecMan and should set exitCode", sec.exitCode);
- ExecutionError.assertExitCode("Execution has to finish without problems", sec.exitCode);
- } finally {
- sec.setActive(false);
- }
- }
-
- protected static final class ExecutionError extends AssertionFailedError {
- public final int exitCode;
- public ExecutionError(String msg, int e) {
- super(msg);
- this.exitCode = e;
- }
- private static void assertExitCode(String msg, int e) {
- if (e != 0) {
- throw new ExecutionError(
- msg + " was: " + e + "\nOutput: " + out.toString()
- + "\nError: " + err.toString(),
- e);
- }
- }
- }
-
- private static class MySecExc extends SecurityException {
- @Override
- public void printStackTrace() {
- }
- @Override
- public void printStackTrace(PrintStream ps) {
- }
- @Override
- public void printStackTrace(PrintWriter ps) {
- }
- }
-
- private static class MySecMan extends SecurityManager {
- public Integer exitCode;
- private boolean active;
- @Override
- public void checkExit(int status) {
- if (active) {
- exitCode = status;
- throw new MySecExc();
- }
- }
- @Override
- public void checkPermission(Permission perm, Object context) {
- }
- @Override
- public void checkPermission(Permission perm) {
- /*
- if (perm instanceof RuntimePermission) {
- if (perm.getName ().equals ("setIO")) {
- throw new MySecExc ();
- }
- }
- */
- }
- @Override
- public void checkMulticast(InetAddress maddr) {
- }
- @Override
- public void checkAccess(ThreadGroup g) {
- }
- @Override
- public void checkWrite(String file) {
- }
- @Override
- public void checkLink(String lib) {
- }
- @Override
- public void checkExec(String cmd) {
- }
- @Override
- public void checkDelete(String file) {
- }
- @Override
- public void checkPackageAccess(String pkg) {
- }
- @Override
- public void checkPackageDefinition(String pkg) {
- }
- @Override
- public void checkPropertyAccess(String key) {
- }
- @Override
- public void checkRead(String file) {
- }
- @Override
- public void checkSecurityAccess(String target) {
- }
- @Override
- public void checkWrite(FileDescriptor fd) {
- }
- @Override
- public void checkListen(int port) {
- }
- @Override
- public void checkRead(FileDescriptor fd) {
- }
- @SuppressWarnings("deprecation")
- @Override
- public void checkMulticast(InetAddress maddr, byte ttl) {
- }
- @Override
- public void checkAccess(Thread t) {
- }
- @Override
- public void checkConnect(String host, int port, Object context) {
- }
- @Override
- public void checkRead(String file, Object context) {
- }
- @Override
- public void checkConnect(String host, int port) {
- }
- @Override
- public void checkAccept(String host, int port) {
- }
- @Override
- public void checkSetFactory() {
- }
- @Override
- public void checkCreateClassLoader() {
- }
- @Override
- public void checkPrintJobAccess() {
- }
- @Override
- public void checkPropertiesAccess() {
- }
- void setActive(boolean b) {
- active = b;
- }
- } // end of MySecMan
-
+ }
}
diff --git a/nbbuild/test/unit/src/org/netbeans/nbbuild/TestDepsTest.java b/nbbuild/test/unit/src/org/netbeans/nbbuild/TestDepsTest.java
index 661124fdc7dc..9cda174de060 100644
--- a/nbbuild/test/unit/src/org/netbeans/nbbuild/TestDepsTest.java
+++ b/nbbuild/test/unit/src/org/netbeans/nbbuild/TestDepsTest.java
@@ -23,6 +23,9 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.Project;
+import org.junit.Rule;
/**
*
@@ -30,6 +33,9 @@
*/
public class TestDepsTest extends TestBase {
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
+
public TestDepsTest(java.lang.String testName) {
super(testName);
}
@@ -37,23 +43,30 @@ public TestDepsTest(java.lang.String testName) {
@Override
protected void setUp() throws Exception {
super.setUp();
+ System.clearProperty("project.file");
ModuleListParserTest.deleteCaches();
}
public void testDepsTest () throws Exception {
// create test
File projectxml = extractFile(TestDepsTest.class.getResourceAsStream("TestDepsProject.xml"),"project.xml");
- execute ("TestDeps.xml", new String[] { "-verbose", "-Dproject.file=" + projectxml, "test-deps" });
+ System.setProperty("project.file", projectxml.getAbsolutePath());
+ buildRule.configureProject(getBuildFileInClassPath("TestDeps.xml"),Project.MSG_VERBOSE);
+ buildRule.executeTarget("test-deps");
}
+
public void testDepsNoTestDeps() throws Exception {
File projectxml = extractFile(TestDepsTest.class.getResourceAsStream("TestDepsProjectNoTestDeps.xml"),"project.xml");
- execute ("TestDeps.xml", new String[] { "-verbose", "-Dproject.file=" + projectxml, "test-deps-no-test-deps" });
-
+ System.setProperty("project.file", projectxml.getAbsolutePath());
+ buildRule.configureProject(getBuildFileInClassPath("TestDeps.xml"),Project.MSG_VERBOSE);
+ buildRule.executeTarget("test-deps-no-test-deps");
}
+
public void testMisingModuleEntryTestDeps() throws Exception {
File projectxml = extractFile(TestDepsTest.class.getResourceAsStream("TestDepsMissingModuleEntry.xml"),"project.xml");
- execute ("TestDeps.xml", new String[] { "-verbose", "-Dproject.file=" + projectxml, "test-deps-missing-module-entry-test-deps" });
-
+ System.setProperty("project.file", projectxml.getAbsolutePath());
+ buildRule.configureProject(getBuildFileInClassPath("TestDeps.xml"),Project.MSG_VERBOSE);
+ buildRule.executeTarget("test-deps-missing-module-entry-test-deps");
}
private File extractFile(InputStream is, String fileName) throws IOException {