update path of gitinfo to be aside user.build.properties (#1527)
* add git build info to gitignore
* change folder for gitinfo
* clean up + use env variable
* populate gitinfo
* finish cleanup
* more cleanup ctd
* gitinfo is generated, no needs header
* manage info in bundle
* get previous Apache NetBeans as coma separated string
* zipfileset fix
diff --git a/.gitignore b/.gitignore
index 08c3a9f..4da9c5f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,6 +30,8 @@
/nbbuild/testuserdir/
/nbbuild/*.zip
/nbbuild/user.build.properties
+/nbbuild/gitinfo.properties
+/nbbuild/netbeansrelease.properties
/nbi/engine/native/*/*/dist/
/nb-javac/
/java.source.nbjavac/test/test-nb-javac/nbproject/private/
diff --git a/nbbuild/antsrc/org/netbeans/nbbuild/HgExec.java b/nbbuild/antsrc/org/netbeans/nbbuild/HgExec.java
deleted file mode 100644
index 9aaff2f..0000000
--- a/nbbuild/antsrc/org/netbeans/nbbuild/HgExec.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.netbeans.nbbuild;
-
-import java.io.File;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.taskdefs.ExecTask;
-import org.apache.tools.ant.types.Commandline;
-
-/**
- * Just like {@code <exec>} but fixes the executable as {@code hg} (Mercurial).
- * The advantage is that it also checks for variants like {@code hg.cmd} etc.
- * See issue #134636.
- */
-public class HgExec extends ExecTask {
-
- public HgExec() {
- List<String> cmd = hgExecutable();
- super.setExecutable(cmd.get(0));
- for (String arg : cmd.subList(1, cmd.size())) {
- createArg().setValue(arg);
- }
- }
-
- @Override
- public void setCommand(Commandline cmdl) {
- throw new BuildException("Cannot call this");
- }
-
- @Override
- public void setExecutable(String value) {
- throw new BuildException("Cannot call this");
- }
-
- /**
- * Get a command to run Mercurial.
- * For Windows users, {@link Runtime#exec} does not work directly on {@code *.bat} / {@code *.cmd} files.
- * Find what the desired Hg executable form is in the path and call it appropriately.
- */
- public static List<String> hgExecutable() {
- String path = System.getenv("Path");
- if (path != null) {
- for (String component : path.split(File.pathSeparator)) {
- if (new File(component, "hg.bat").isFile() || new File(component, "hg.cmd").isFile()) {
- return Arrays.asList("cmd", "/c", "hg");
- } else if (new File(component, "hg.exe").isFile() || new File(component, "hg").isFile()) {
- return Collections.singletonList("hg");
- }
- }
- }
- return Collections.singletonList("git");
- }
-
-}
diff --git a/nbbuild/antsrc/org/netbeans/nbbuild/ParseGitBranch.java b/nbbuild/antsrc/org/netbeans/nbbuild/ParseGitBranch.java
deleted file mode 100644
index 0c66f31..0000000
--- a/nbbuild/antsrc/org/netbeans/nbbuild/ParseGitBranch.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.netbeans.nbbuild;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Task;
-import java.io.Reader;
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.LineNumberReader;
-
-/**
- *
- * @author skygo
- */
-public class ParseGitBranch extends Task {
-
- /**
- * data to parse
- */
- private String data;
-
- public void setData(String data) {
- this.data = data;
- }
-
- /**
- * properties to set
- */
- private String propertyName;
-
- public void setProperty(String propertyName) {
- this.propertyName = propertyName;
- }
-
- @Override
- public void execute() throws BuildException {
- super.execute();
- Reader dataReader = new StringReader(data);
- String firstLine = null;
- String secondLine = null;
- try (LineNumberReader r = new LineNumberReader(dataReader);) {
- firstLine = r.readLine();
- secondLine = r.readLine();
- } catch (IOException ex) {
- throw new BuildException("Problem reading information for detached head");
- }
- //if (secondLine != null) {
- // throw new BuildException("Problem parsing git information for detached head : too many line");
- //}
- if (secondLine != null || firstLine == null || firstLine.trim().isEmpty()) {
- // Assume master if PR or detached HEAD on Travis, etc.
- getProject().setProperty(propertyName, "master");
- } else {
- String[] splited = firstLine.trim().split(" ");
- long count = splited[0].chars().filter(ch -> ch == '/').count();
- if (count != 1) {
- throw new BuildException("Problem parsing git information" + count);
- } else {
- getProject().setProperty(propertyName, splited[0].split("/")[1]);
- }
- }
- }
-}
diff --git a/nbbuild/antsrc/org/netbeans/nbbuild/ReleaseJsonProperties.java b/nbbuild/antsrc/org/netbeans/nbbuild/ReleaseJsonProperties.java
index 4ab5422..31bbf68 100644
--- a/nbbuild/antsrc/org/netbeans/nbbuild/ReleaseJsonProperties.java
+++ b/nbbuild/antsrc/org/netbeans/nbbuild/ReleaseJsonProperties.java
@@ -116,7 +116,8 @@
}
// sort all information
Collections.sort(ri);
- // build a sorted xml
+ // build a sorted xml
+
for (ReleaseInfo releaseInfo : ri) {
log(releaseInfo.toString());
for (Object milestone : releaseInfo.milestones) {
@@ -134,6 +135,12 @@
if (requiredbranchinfo == null) {
throw new BuildException("No Release Information found for branch '" + branch + "', update json file section");
}
+ List<String> updateValues = new ArrayList<>();
+ for (ReleaseInfo releaseInfo : ri) {
+ if (releaseInfo.position < requiredbranchinfo.position) {
+ updateValues.add(releaseInfo.version);
+ }
+ }
// populate properties for api changes
getProject().setProperty("previous.release.year", Integer.toString(requiredbranchinfo.previousReleaseDate.getYear()));
getProject().setProperty("previous.release.month", String.format("%02d", requiredbranchinfo.previousReleaseDate.getMonthValue()));
@@ -170,7 +177,7 @@
config.write(("metabuild.PluginPortalURL=" + requiredbranchinfo.pluginsurl + "\n").getBytes());
// used for cache and user dir
config.write(("metabuild.RawVersion=" + requiredbranchinfo.version + optionalversion + "\n").getBytes());
-
+ config.write(("metabuild.apachepreviousversion=" + String.join(",", updateValues) + "\n").getBytes());
if (branch.equals("master")) {
config.write(("metabuild.ComputedSplashVersion=DEV (Build {0})\n").getBytes());
config.write(("metabuild.ComputedTitleVersion=DEV {0}\n").getBytes());
diff --git a/nbbuild/antsrc/org/netbeans/nbbuild/ValidateHgConfiguration.java b/nbbuild/antsrc/org/netbeans/nbbuild/ValidateHgConfiguration.java
deleted file mode 100644
index f737c38..0000000
--- a/nbbuild/antsrc/org/netbeans/nbbuild/ValidateHgConfiguration.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.netbeans.nbbuild;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
-
-/**
- * Look for common problems in your Hg configuration and warn about them.
- */
-public class ValidateHgConfiguration extends Task {
-
- private File root;
- /** Location of NB source root. */
- public void setRoot(File root) {
- this.root = root;
- }
-
- @Override
- public void execute() throws BuildException {
- File dotHg = new File(root, ".hg");
- if (!dotHg.isDirectory()) {
- log(root + " is not a Mercurial repository", Project.MSG_VERBOSE);
- return;
- }
- List<String> hgExecutable = HgExec.hgExecutable();
- try {
- List<String> commandAndArgs = new ArrayList<>(hgExecutable);
- commandAndArgs.add("--config");
- commandAndArgs.add("extensions.churn="); // added to hgext right before 1.0 release
- commandAndArgs.add("showconfig");
- Process p = new ProcessBuilder(commandAndArgs).directory(root).start();
- BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
- boolean foundUserName = false, foundCrlfHook = false;
- String line;
- while ((line = r.readLine()) != null) {
- if (line.matches("hooks\\.pretxncommit\\..+=python:(hgext\\.)?win32text\\.forbidcrlf")) {
- foundCrlfHook = true;
- } else if (line.matches("ui\\.username=(.+ <)?\\w+@netbeans\\.org>?")) {
- foundUserName = true;
- }
- }
- if (!foundUserName) {
- log("======== WARNING ========\n" +
- "You need to configure a Mercurial username\n" +
- "if you intend to push changes to NetBeans repositories.\n" +
- "Format (in ~/.hgrc or Mercurial.ini):\n" +
- "[ui]\n" +
- "username = Robert Q. Hacker <rhacker@netbeans.org>\n" +
- "=========================", Project.MSG_WARN);
- }
- if (!foundCrlfHook) {
- log("======== WARNING ========\n" +
- "You need to guard against committing carriage returns into Mercurial\n" +
- "if you intend to push changes to NetBeans repositories.\n" +
- "Format (in ~/.hgrc or Mercurial.ini):\n" +
- "[hooks]\n" +
- "pretxncommit.crlf = python:hgext.win32text.forbidcrlf\n" +
- "=========================", Project.MSG_WARN);
- }
- r = new BufferedReader(new InputStreamReader(p.getErrorStream()));
- while ((line = r.readLine()) != null) {
- if (line.contains("failed to import extension churn")) {
- log("======== WARNING ========\n" +
- "You seem to be using a version of Mercurial older than 1.0.\n" +
- "Please upgrade as your version may have serious bugs fixed in later versions.\n" +
- "=========================", Project.MSG_WARN);
- }
- }
- } catch (IOException x) {
- log("Could not verify Hg configuration: " + x, Project.MSG_WARN);
- }
- }
-
-}
diff --git a/nbbuild/build.xml b/nbbuild/build.xml
index b1e5445..a8b68cf 100644
--- a/nbbuild/build.xml
+++ b/nbbuild/build.xml
@@ -60,14 +60,10 @@
<classpath>
<pathelement location="${ant.core.lib}"/>
</classpath>
- <include name="org/netbeans/nbbuild/HgExec.java"/>
- <include name="org/netbeans/nbbuild/ValidateHgConfiguration.java"/>
<include name="org/netbeans/nbbuild/extlibs/DeregisterExternalHook.java"/>
<include name="org/netbeans/nbbuild/extlibs/DownloadBinaries.java"/>
<compilerarg line="-Xlint -Xlint:-serial"/>
</javac>
- <taskdef name="validate-hg-configuration" classname="org.netbeans.nbbuild.ValidateHgConfiguration" classpath="${build.ant.classes.dir}"/>
- <validate-hg-configuration root=".."/>
<taskdef name="deregisterexternalhook" classname="org.netbeans.nbbuild.extlibs.DeregisterExternalHook" classpath="${build.ant.classes.dir}"/>
<deregisterexternalhook root=".."/>
<taskdef name="downloadbinaries" classname="org.netbeans.nbbuild.extlibs.DownloadBinaries" classpath="${build.ant.classes.dir}"/>
@@ -122,16 +118,15 @@
<get dest="${metabuild.releasejson}" skipexisting="false" src="${metabuild.jsonurl}" />
<!-- get branches and git information -->
<antcall target="getgitinformation" />
- <!-- hardcoded item for testing
-<echo file="${nb_all}/nbbuild/build/gitinfo.properties" >metabuild.branch=release111
-metabuild.hash=f56623c16cc2cbc4a381508562545b13de91437e
-</echo>
- -->
<!-- javadoc content filtering -->
<taskdef name="setjavadoc" classname="org.netbeans.nbbuild.SetApidocClustersConfig" classpath="${nbantext.jar}"/>
+ <!-- read info from gitinfo.properties , if present in source bundle copy gitinfo-->
+ <copy file="${nb_all}/nbbuild/gitinfo.properties" tofile="${nb_all}/nbbuild/build/gitinfo.properties" failonerror="false"/>
+ <copy file="${nb_all}/nbbuild/netbeansrelease.properties" tofile="${nb_all}/nbbuild/build/netbeansrelease.properties" failonerror="false"/>
<property file="${nb_all}/nbbuild/build/gitinfo.properties"/>
+ <property file="${nb_all}/nbbuild/build/netbeansrelease.properties"/>
<setjavadoc branch="${metabuild.branch}"/>
- <echo message="${metabuild.branch}"/>
+ <echo message="Building branch: ${metabuild.branch}"/>
<property name="releasejson" value="${nb_all}/nbbuild/build/netbeansrelease.json"/>
<property name="xmlrelease" value="${nb_all}/nbbuild/build/netbeansrelease.xml"/>
<property name="propertiesrelease" value="${nb_all}/nbbuild/build/netbeansrelease.properties"/>
@@ -146,48 +141,51 @@
<releasejson file="${releasejson}" xmloutput="${xmlrelease}" propertiesoutput="${propertiesrelease}" branch="${metabuild.branch}" hash="${metabuild.hash}"/>
<!--<fail />-->
</target>
- <target name="-git.ispresent">
- <condition property="metabuild.isgitrepo" value="true" else="false">
- <available type="dir" file="../.git"/>
- </condition>
+ <target name="-gitinfo.ispresent">
+ <available file="${nb_all}/nbbuild/build/gitinfo.properties" property="gitinfo.present" />
</target>
- <target name="-git.down" unless="${metabuild.isgitrepo}" depends="-git.ispresent">
- <!-- no git, assuming master, but should try other option -->
- <echo file="${nb_all}/nbbuild/build/gitinfo.properties" >metabuild.branch=master</echo>
- </target>
- <target name="-git.up" if="${metabuild.isgitrepo}" depends="-git.ispresent">
- <taskdef name="gitexec" classname="org.netbeans.nbbuild.HgExec" classpath="${nbantext.jar}"/>
- <gitexec outputproperty="git.hash.properties">
- <arg value="rev-parse"/>
- <arg value="HEAD"/>
- </gitexec>
- <gitexec outputproperty="git.branch.properties">
- <arg value="rev-parse"/>
- <arg value="--abbrev-ref"/>
- <arg value="HEAD"/>
- </gitexec>
- <echo message="branch ${git.branch.properties}" />
- <gitexec outputproperty="git.branchdetached.bulk.properties">
- <arg value="branch"/>
- <arg value="--remote"/>
- <arg value="--verbose"/>
- <arg value="--no-abbrev"/>
- <arg value="--contains"/>
- </gitexec>
- <echo message="detached ${git.branchdetached.bulk.properties}" />
- <!-- branch is HEAD implies detached -->
- <condition property="invalidbranch">
- <equals arg1="HEAD" arg2="${git.branch.properties}"/>
+ <target name="-git.down" unless="${gitinfo.present}" depends="-gitinfo.ispresent">
+ <!-- try to get information from jenkins or travis -->
+ <property environment="env"/>
+ <condition property="metabuild.branch" value="${env.GIT_BRANCH}" >
+ <isset property="env.GIT_BRANCH" />
</condition>
- <taskdef name="parsebranch" classname="org.netbeans.nbbuild.ParseGitBranch" classpath="${nbantext.jar}"/>
- <parsebranch if:set="invalidbranch" data="${git.branchdetached.bulk.properties}" property="git.branchdetached.parsed.properties" />
- <!-- keep echo file at begining of line, build git data -->
- <echo unless:set="invalidbranch" file="${nb_all}/nbbuild/build/gitinfo.properties" >metabuild.branch=${git.branch.properties}
-metabuild.hash=${git.hash.properties}
-</echo>
- <echo if:set="invalidbranch" file="${nb_all}/nbbuild/build/gitinfo.properties" >metabuild.branch=${git.branchdetached.parsed.properties}
-metabuild.hash=${git.hash.properties}
-</echo>
+ <condition property="metabuild.branch" value="${env.TRAVIS_BRANCH}" >
+ <isset property="env.TRAVIS_BRANCH" />
+ </condition>
+ <condition property="metabuild.branch" value="${metabuild.branch}" >
+ <isset property="metabuild.branch" />
+ </condition>
+ <condition property="metabuild.branch" value="master" >
+ <not>
+ <isset property="metabuild.branch" />
+ </not>
+ </condition>
+ <condition property="metabuild.hash" value="${env.GIT_COMMIT}" >
+ <isset property="env.GIT_COMMIT" />
+ </condition>
+ <condition property="metabuild.hash" value="${env.TRAVIS_COMMIT}" >
+ <isset property="env.TRAVIS_COMMIT" />
+ </condition>
+ <condition property="metabuild.hash" value="${metabuild.hash}" >
+ <isset property="metabuild.hash" />
+ </condition>
+ <echo message="Processing build with branch ${metabuild.branch} and hash ${metabuild.hash}" />
+ <!-- if hash not present do not fail -->
+ <fail message="Branch not found use -Dmetabuild.branch=branchName " >
+ <condition>
+ <not>
+ <isset property="metabuild.branch"/>
+ </not>
+ </condition>
+ </fail>
+ <echo unless:set="metabuild.hash" file="${nb_all}/nbbuild/build/gitinfo.properties" >metabuild.branch=${metabuild.branch}</echo>
+ <echo if:set="metabuild.hash" file="${nb_all}/nbbuild/build/gitinfo.properties" >metabuild.branch=${metabuild.branch}
+metabuild.hash=${metabuild.hash}</echo>
+ </target>
+ <target name="-git.up" if="${gitinfo.present}" depends="-gitinfo.ispresent">
+ <property file="${nb_all}/nbbuild/build/gitinfo.properties"/>
+ <echo message="Processing build with branch ${metabuild.branch} and hash ${metabuild.hash}" />
</target>
<target name="getgitinformation" depends="-git.up,-git.down" />
<target name="download-all-extbins" unless="ext.binaries.downloaded" depends="bootstrap">
@@ -1779,6 +1777,8 @@
<zipfileset file="${nb.build.dir}/LICENSE" />
<zipfileset dir="${nb.build.dir}/licenses" includes="**" prefix="licenses" />
<zipfileset file="${source.zip.readme}" fullpath="README.md" erroronmissingarchive="false" />
+ <zipfileset file="${nb_all}/nbbuild/build/netbeansrelease.properties" fullpath="nbbuild/netbeansrelease.properties" erroronmissingarchive="false"/>
+ <zipfileset file="${nb_all}/nbbuild/build/gitinfo.properties" fullpath="nbbuild/gitinfo.properties" erroronmissingarchive="false" />
</zip>
</target>
diff --git a/nbbuild/rat-exclusions.txt b/nbbuild/rat-exclusions.txt
index 867bfbd..910cfba 100644
--- a/nbbuild/rat-exclusions.txt
+++ b/nbbuild/rat-exclusions.txt
@@ -23,6 +23,9 @@
nbbuild/netbeans/**
nbbuild/testuserdir/**
nbbuild/user.build.properties
+###### generated build artefact
+nbbuild/gitinfo.properties
+nbbuild/netbeansrelease.properties
###### user-specific files
**/nbproject/private/**