-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MBUILDCACHE-105] Executing 'clean process-test-classes' then 'clean verify' leads to empty jars #176
Open
reda-alaoui
wants to merge
2
commits into
apache:master
Choose a base branch
from
Cosium:MBUILDCACHE-105
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[MBUILDCACHE-105] Executing 'clean process-test-classes' then 'clean verify' leads to empty jars #176
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/test/java/org/apache/maven/buildcache/its/Issue105Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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.apache.maven.buildcache.its; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Arrays; | ||
|
||
import org.apache.commons.compress.archivers.jar.JarArchiveEntry; | ||
import org.apache.commons.compress.archivers.jar.JarArchiveInputStream; | ||
import org.apache.maven.buildcache.its.junit.IntegrationTest; | ||
import org.apache.maven.it.VerificationException; | ||
import org.apache.maven.it.Verifier; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* @author Réda Housni Alaoui | ||
*/ | ||
@IntegrationTest("src/test/projects/mbuildcache-105") | ||
class Issue105Test { | ||
|
||
public static final String BUILT_JAR = "target/simple-0.0.1-SNAPSHOT.jar"; | ||
|
||
@Test | ||
void simple(Verifier verifier) throws VerificationException, IOException { | ||
verifier.setAutoclean(false); | ||
|
||
verifier.setLogFileName("../log-1.txt"); | ||
verifier.executeGoals(Arrays.asList("clean", "process-test-classes")); | ||
verifier.verifyErrorFreeLog(); | ||
|
||
verifier.setLogFileName("../log-2.txt"); | ||
verifier.executeGoals(Arrays.asList("clean", "verify")); | ||
verifier.verifyErrorFreeLog(); | ||
verifier.verifyTextInLog("Cached build doesn't include phase 'package', cannot restore"); | ||
verifier.verifyFilePresent(BUILT_JAR); | ||
|
||
Path jarPath = Paths.get(verifier.getBasedir()).resolve(BUILT_JAR); | ||
assertJarEntryExists(jarPath, "org/apache/maven/buildcache/Test.class"); | ||
} | ||
|
||
private void assertJarEntryExists(Path jarPath, String name) throws IOException { | ||
try (JarArchiveInputStream inputStream = new JarArchiveInputStream(Files.newInputStream(jarPath))) { | ||
JarArchiveEntry entry = inputStream.getNextJarEntry(); | ||
while (entry != null) { | ||
if (entry.getName().equals(name)) { | ||
return; | ||
} | ||
entry = inputStream.getNextJarEntry(); | ||
} | ||
} | ||
Assertions.fail("No JAR entry found for name '" + name + "'"); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/projects/mbuildcache-105/.mvn/maven-build-cache-config.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!--- | ||
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. | ||
--> | ||
<cache xmlns="http://maven.apache.org/BUILD-CACHE-CONFIG/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/BUILD-CACHE-CONFIG/1.0.0 https://maven.apache.org/xsd/build-cache-config-1.0.0.xsd"> | ||
</cache> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!-- | ||
|
||
Copyright 2021 the original author or authors. | ||
|
||
Licensed 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. | ||
|
||
--> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.apache.maven.caching.test.mbuildcache-105</groupId> | ||
<artifactId>simple</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<build> | ||
<extensions> | ||
<extension> | ||
<groupId>org.apache.maven.extensions</groupId> | ||
<artifactId>maven-build-cache-extension</artifactId> | ||
<version>${projectVersion}</version> | ||
</extension> | ||
</extensions> | ||
</build> | ||
|
||
</project> |
24 changes: 24 additions & 0 deletions
24
src/test/projects/mbuildcache-105/src/main/java/org/apache/maven/buildcache/Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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.apache.maven.buildcache; | ||
|
||
class Test | ||
{ | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the current implementation, the 'analyzeResult' returns partial success in lines 277-278 as expected.
More accurate implementation could support pre-compile phases - 'save' and restore generated sources and continue with compile. This will allow restoring missing sources from the cache and potentially saving time on the code generation. Could be handy in IDEs which could faster compile the project after a branch switch (if generated sources are restored).
The second concern is that we still process builds that will never be used in the 'save'. Save and restore should be consistent, and the situation when cached builds are not usable should also be considered for improvement.
Though overall, as a quick fix, this change seems legitimate, it feels like restoring generated sources and commencing with compilation would be more optimal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlexanderAshitkin I agree with you.
At first I wanted to fix the extension to make it able to save cache state on phase < package. But there is this sentence in the documentation:
I could not find the reason of this constraint, so I made sure this fix respects the latter. Also the fix should be quick to merge to prevent people from getting into trouble.
I also think this extension should not limit itself to phases >=
package
. We can still come back to that later.