exporting patch: # HG changeset patch # User Eric Barboni # Date 1426523094 -3600 # Mon Mar 16 17:24:54 2015 +0100 # Node ID 05265be63a7f99b7566846dcda7a1e58d546620f # Parent 692214e695d49a7261c802e28f49f62ab4273531 [mq]: maven.diff diff --git a/maven/src/org/netbeans/modules/maven/execute/cmd/ShellConstructor.java b/maven/src/org/netbeans/modules/maven/execute/cmd/ShellConstructor.java --- a/maven/src/org/netbeans/modules/maven/execute/cmd/ShellConstructor.java +++ b/maven/src/org/netbeans/modules/maven/execute/cmd/ShellConstructor.java @@ -46,6 +46,7 @@ import java.util.ArrayList; import java.util.List; import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.modules.maven.options.MavenSettings; import org.openide.util.Utilities; /** @@ -65,7 +66,23 @@ //if maven.bat file is in space containing path, we need to quote with simple quotes. String quote = "\""; List toRet = new ArrayList(); - String ex = Utilities.isWindows() ? "mvn.bat" : "mvn"; //NOI18N + String ex = "mvn"; //NOI18N + if (Utilities.isWindows()) { + String version = MavenSettings.getCommandLineMavenVersion(mavenHome); + if (null == version) { + ex = "mvn.bat"; // NOI18N + } else { + String[] v = version.split("\\."); // NOI18N + int major = Integer.parseInt(v[0]); + int minor = Integer.parseInt(v[1]); + // starting with 3.3.0 maven stop using .bat file + if ((major < 3) || (major == 3 && minor < 3)) { + ex = "mvn.bat"; //NOI18N + } else { + ex = "mvn.cmd"; //NOI18N + } + } + } File bin = new File(mavenHome, "bin" + File.separator + ex);//NOI18N toRet.add(quoteSpaces(bin.getAbsolutePath(), quote)); diff --git a/maven/test/unit/data/mavenmock/2.2/lib/fake221.jar b/maven/test/unit/data/mavenmock/2.2/lib/fake221.jar new file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0256f76e3844814b4da6ef098b9e6877b42cfb68 GIT binary patch literal 1001 zc$^FHW@h1HVBlb2;A|*xV?Y9&3@i-3t|5-Po_=on|4uP51i+PY0F~}$;NngPDg$8= zAciaTb@cOea}5sB^L6u0%*#wmEiTawOD!tS%+Iq@Fw`^P<#NnJ5^*d@OwLGE0Ez)6 zE%i)zxtxnq6H8K4be$?e>MisP;!O;6lZ;FiH2jMalXFrPob!tc@{1BnfciCgxp=t( zaQcBC*+yqZ6b7oN!{f9qEs}4dYkKx*#HdyVN22s zD#*{(D=5k@NG&SKOf4>h1gou)o{^p*S9(!?X@O^oExLZLM4;ld#N-m79KxsoZ$>5& zX55JZ0t6V|Ix-+T5t1|zTCpV#7+BJX5==-*1)t^oa2Ck&BiP~;w`K(t%^!)1W89`` oqnM`8NMf9$8jK$6h)}8^&0y3t5a7+q1~P^X2u}bF;${Nz0Q^hb7ytkO diff --git a/maven/test/unit/data/mavenmock/3.0.5/lib/fake305.jar b/maven/test/unit/data/mavenmock/3.0.5/lib/fake305.jar new file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..9e7fa334431a2cb33a50642dc4c35457c6230805 GIT binary patch literal 1001 zc$^FHW@h1HVBlb2h^#MgV?Y9&3@i-3t|5-Po_=on|4uP51i+O>0F~}$;NngPDg$8= zAciaTb@cOea}5sB^L6u0%*#wmEiTawOD!tS%+Iq@Fw`^P<#NnJ5^*d@OwLGE0Ez)6 zE%i)zxtxnq6H8K4be$?e>MisP;!O;6lZ;FiH2jMalXFrPob!tc@{1BnfciCgxp=t( zaQcBC*+yqZ6b7oN!{f9qEs}4f`6uU*#HdyVN22s zD#*{(D=5k@NG&SKOf4>h1govFo`IezS9(!?X@O^oExLZLM4;ld#N-m79KxsoZ$>5& zX55JZ0t6V|Ix-+T5t1|zTCpV#7+BJX5==-*1)t^oa2Ck&BiP~;w`K(t%^!)1W89`` oqnM`8NMf9$8jK$6h)}8^&0y3t5a7+q1~P^X2u}bF;${Nz0JG8Gp8x;= diff --git a/maven/test/unit/data/mavenmock/3.3.1/lib/fake331.jar b/maven/test/unit/data/mavenmock/3.3.1/lib/fake331.jar new file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..f482219943b81b7197142cf0de93bbf9f9c76dd9 GIT binary patch literal 1001 zc$^FHW@h1HVBlb2aH%hFV?Y9&3@i-3t|5-Po_=on|4uP51i+O#1C{P(;NngPDg$8= zAciaTb@cOea}5sB^L6u0%*#wmEiTawOD!tS%+Iq@Fw`^P<#NnJ5^*d@OwLGE0Ez)6 zE%i)zxtxnq6H8K4be$?e>MisP;!O;6lZ;FiH2jMalXFrPob!tc@{1BnfciCgxp=t( zaQcBC*+yqZ6b7oN!{f9qEs}43e%dkZGZ-Vuq9~* z73AmY6%^$cq!yKArWTh$g4Nbo&sfipE4?Vcw7@gP7F|DAB2aN!VsZ&k4q;S)HzSh> zGw#Fy0Rjwf9T||F2uT_Ut=JL=3@m9x2_~eZg3oe(I16O?5o~daTeAX+=8r_hF>cee oQB2ckBr(oW4MvZ3L?~5|W-w|R2=HcQ0~x~xgeQOoaWjE<0F<@eGynhq diff --git a/maven/test/unit/data/mavenmock/4.0.0/lib/fake400.jar b/maven/test/unit/data/mavenmock/4.0.0/lib/fake400.jar new file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a82a2a5308f8caa02df71c1302046f61d5a1c1b0 GIT binary patch literal 1001 zc$^FHW@h1HVBlb2P;Mx2V?Y9&3@i-3t|5-Po_=on|4uP51i+Ol0hR7%;NngPDg$8= zAciaTb@cOea}5sB^L6u0%*#wmEiTawOD!tS%+Iq@Fw`^P<#NnJ5^*d@OwLGE0Ez)6 zE%i)zxtxnq6H8K4be$?e>MisP;!O;6lZ;FiH2jMalXFrPob!tc@{1BnfciCgxp=t( zaQcBC*+yqZ6b7oN!{f9qEs}4=7zAh+W-v!VN22s zD#*{(D=5k@NG&SKOf4>h1gouyo`IeLS9(!?X@O^oExLZLM4;ld#N-m79KxsoZ$>5& zX55JZ0t6V|Ix-+T5t1|zTCpV#7+BJX5==-*1)t^oa2Ck&BiP~;w`K(t%^!)1W89`` oqnM`8NMf9$8jK$6h)}8^&0y3t5a7+q1~P^X2u}bF;${Nz07Tr|r2qf` diff --git a/maven/test/unit/src/org/netbeans/modules/maven/execute/cmd/ShellConstructorTest.java b/maven/test/unit/src/org/netbeans/modules/maven/execute/cmd/ShellConstructorTest.java new file mode 100644 --- /dev/null +++ b/maven/test/unit/src/org/netbeans/modules/maven/execute/cmd/ShellConstructorTest.java @@ -0,0 +1,123 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2015 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2015 Sun Microsystems, Inc. + */ +package org.netbeans.modules.maven.execute.cmd; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.List; +import org.junit.Test; +import org.netbeans.junit.NbTestCase; +import org.netbeans.modules.maven.options.MavenSettings; +import org.openide.util.Utilities; + +/** + * + * + */ +public class ShellConstructorTest extends NbTestCase { + + public ShellConstructorTest(String name) throws FileNotFoundException, IOException { + super(name); + } + + private void resetOs() throws Exception { + // hack to call reset OS of BaseUtilies + Class classz = Class.forName("org.openide.util.BaseUtilities"); + Method m = classz.getDeclaredMethod("resetOperatingSystem"); + m.setAccessible(true); + m.invoke(null); + } + + /** + * Test of construct method, of class ShellConstructor. + * + * @throws java.lang.Exception + */ + @Test + public void testShellConstructoronLinux() throws Exception { + resetOs(); + String previous = System.getProperty("os.name"); + System.getProperties().put("os.name", "Linux"); + assertFalse("Must be linux", Utilities.isWindows()); + System.getProperties().put("os.name", previous); + + assertTrue("2.2 linux", getCLI("2.2", "2.2.1", "mvn")); + assertTrue("3.0.5 linux", getCLI("3.0.5", "3.0.5", "mvn")); + assertTrue("3.3.1 linux", getCLI("3.3.1", "3.3.1", "mvn")); + assertTrue("4.0.0 linux", getCLI("4.0.0", "4.0.0", "mvn")); + System.getProperties().put("os.name", previous); + resetOs(); + + } + + @Test + public void testShellconstructoronWindows() throws Exception { + resetOs(); + String previous = System.getProperty("os.name"); + System.getProperties().put("os.name", "Windows "); + assertTrue("Must be windows", Utilities.isWindows()); + System.getProperties().put("os.name", previous); + assertTrue("2.2 windows", getCLI("2.2", "2.2.1", "mvn.bat")); + assertTrue("3.0.5 windows", getCLI("3.0.5", "3.0.5", "mvn.bat")); + assertTrue("3.3.1 windows", getCLI("3.3.1", "3.3.1", "mvn.cmd")); + assertTrue("4.0.0 windows", getCLI("4.0.0", "4.0.0", "mvn.cmd")); + + System.getProperties().put("os.name", previous); + resetOs(); + } + + private boolean getCLI(String folder, String requestedversion, String mvn) { + File sourceJar = new File(this.getDataDir(), "mavenmock/" + folder + "/"); + String version = MavenSettings.getCommandLineMavenVersion(sourceJar); + assertEquals(requestedversion, version); + ShellConstructor shellConstructor = new ShellConstructor(sourceJar); + List construct = shellConstructor.construct(); + if (Utilities.isWindows()) { + assertTrue("cli must contains " + mvn, construct.get(2).contains(mvn)); + } else { + assertTrue("cli must contains " + mvn, construct.get(0).contains(mvn)); + } + return true; + } +}