Skip to content

Commit

Permalink
Merge pull request apache#6514 from sdedic/maven/priming-and-reloads
Browse files Browse the repository at this point in the history
Priming build and reload improvements.
  • Loading branch information
neilcsmith-net authored Oct 24, 2023
2 parents 40a9bb6 + 9f51a38 commit b12970d
Show file tree
Hide file tree
Showing 33 changed files with 1,887 additions and 142 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ jobs:
timeout-minutes: 60
strategy:
matrix:
java: [ '11' ]
java: [ '11', '17' ]
steps:

- name: Set up JDK ${{ matrix.java }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@

primingBuild.snapshot.goals=install
primingBuild.regular.goals=install
skipTests=true
2 changes: 2 additions & 0 deletions java/java.mx.project/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ requires.nb.javac=true

# For testing we need path to the MX executable. The executable is checked out by the buildscript.
test.run.args=-Dorg.netbeans.modules.java.mx.project.test.mxpath=${basedir}/test/unit/data/mx/mx

test.jms.flags=--add-opens=java.base/java.net=ALL-UNNAMED
14 changes: 14 additions & 0 deletions java/maven/apichanges.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ is the proper place.
<!-- ACTUAL CHANGES BEGIN HERE: -->

<changes>
<change id="partial-maven-project">
<api name="general"/>
<summary>Support for partially loaded projects</summary>
<version major="2" minor="161"/>
<date day="3" month="10" year="2023"/>
<author login="sdedic"/>
<compatibility addition="yes" semantic="compatible"/>
<description>
Added a <a href="@TOP@/org/netbeans/modules/maven/api/NbMavenProject.html#getPartialProject-org.apache.maven.project.MavenProject-">
getPratialProject</a> that returns potentially incompletely loaded project instead of a mocked-up fallback (see <a href="@TOP@/org/netbeans/modules/maven/api/NbMavenProject.html#isErrorPlaceholder-org.apache.maven.project.MavenProject-">isErrorPlaceholder()</a>.
Also added a <a href="@TOP@/org/netbeans/modules/maven/api/NbMavenProject.html#isIncomplete-org.apache.maven.project.MavenProject-">isIncomplete()</a> check that checks project's status.
</description>
<class package="org.netbeans.modules.maven.api" name="NbMavenProject"/>
</change>
<change id="runutils-createconfig-action">
<api name="general"/>
<summary></summary>
Expand Down
3 changes: 2 additions & 1 deletion java/maven/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
<package-artifact-from-dir jarbasename="test-lib3-12.6" relpath="projects/dependencies/repo/grp/test-lib3/12.6"/>
<package-artifact-from-dir jarbasename="test-lib4-12.6" relpath="projects/dependencies/repo/grp/test-lib4/12.6"/>
<package-artifact-from-dir jarbasename="test-processor-12.6" relpath="projects/dependencies/repo/grp/test-processor/12.6"/>


<chmod file="${build.test.unit.dir}/data/projects/multiproject/democa/mvnw" perm="ugo+rwx"/>
</target>

</project>
2 changes: 1 addition & 1 deletion java/maven/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ javadoc.apichanges=${basedir}/apichanges.xml
javadoc.arch=${basedir}/arch.xml
javahelp.hs=maven.hs
extra.module.files=maven-nblib/
spec.version.base=2.160.0
spec.version.base=2.161.0

# The CPExtender test fails in library processing (not randomly) since NetBeans 8.2; disabling.
test.excludes=**/CPExtenderTest.class
Expand Down
49 changes: 49 additions & 0 deletions java/maven/src/org/netbeans/modules/maven/NbArtifactFixer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.maven.artifact.DefaultArtifact;
Expand Down Expand Up @@ -105,6 +106,10 @@ public class NbArtifactFixer implements ArtifactFixer {
//instead of workarounds down the road, we set the artifact's file here.
// some stacktraces to maven/aether do set it after querying our code, but some don't for reasons unknown to me.
artifact.setFile(f);
Set<Artifact> s = CAPTURE_FAKE_ARTIFACTS.get();
if (s != null) {
s.add(artifact);
}
return f;
} catch (IOException x) {
Exceptions.printStackTrace(x);
Expand Down Expand Up @@ -149,4 +154,48 @@ private static synchronized File createFallbackPOM(String groupId, String artifa
return fallbackPOM;
}

public interface ExceptionCallable<T, E extends Throwable> {
public T call() throws E;
}

@SuppressWarnings("unchecked")
private static <T extends Throwable> void sneakyThrow(Throwable exception) throws T {
throw (T) exception;
}

/**
* Collects faked artifacts, which would be otherwise hidden in maven infrastructure. The value is only valid during {@link #collectFallbackArtifacts}, which
* can be invoked recursively.
*/
private static ThreadLocal<Set<Artifact>> CAPTURE_FAKE_ARTIFACTS = new ThreadLocal<Set<Artifact>>();

/**
* Performs an operation and collects forged artifacts created during that operation. The invocation can be nested; each invocation gets only artifacts from its own 'level',
* not those from possible nested invocations. The function passes on all runtime exceptions and checked exception thrown by the operation.
*
* @param <T> value produced by the executed operation
* @param <E> exception thrown from the operation
* @param code the operation to call and monitor
* @param collector callback that will get collected artifacts.
* @return
* @throws E
*/
public static <T, E extends Throwable> T collectFallbackArtifacts(ExceptionCallable<T, E> code, Consumer<Set<Artifact>> collector) throws E {
Set<Artifact> save = CAPTURE_FAKE_ARTIFACTS.get();
try {
CAPTURE_FAKE_ARTIFACTS.set(new HashSet<>());
return code.call();
} catch (Error | RuntimeException r) {
throw r;
} catch (Exception ex) {
sneakyThrow(ex);
// unreachable
throw new Error();
} finally {
if (collector != null) {
collector.accept(CAPTURE_FAKE_ARTIFACTS.get());
}
CAPTURE_FAKE_ARTIFACTS.set(save);
}
}
}
Loading

0 comments on commit b12970d

Please sign in to comment.