Skip to content

Commit

Permalink
Ensure that if an archive is built, the repository content is mirrored
Browse files Browse the repository at this point in the history
Also ensure that if a composite is corrupt, a new composite is built
nevertheless.
  • Loading branch information
merks committed Jan 27, 2024
1 parent 3444a70 commit f634d76
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 39 deletions.
103 changes: 64 additions & 39 deletions plugins/org.eclipse.justj.p2/src/org/eclipse/justj/p2/P2Manager.java
Expand Up @@ -38,6 +38,7 @@
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -171,7 +172,7 @@ public void promoteLatestMilestoneUpdateSiteToReleaseUpdateSite() throws Excepti
{
Path milestoneLatest = updateSiteGenerator.getCompositeUpdateSiteDestination("milestone", true);
Path source = updateSiteGenerator.getLatest(milestoneLatest);
ensureSourceMilestoneExists(source);
ensureRepositorySourceExists(source);
String version = updateSiteGenerator.getVersion(source, false);
Path target = updateSiteGenerator.getPromoteUpdateSiteDestination("release", version);
Path primaryTarget = target;
Expand Down Expand Up @@ -200,10 +201,10 @@ public void promoteLatestMilestoneUpdateSiteToReleaseUpdateSite() throws Excepti

/**
* This call-out is called right before this repository will be loaded and can be used to transfer the contents from a remote location to a local location..
* @param source the repository to be loaded
* @param source the repository to be loaded.
* @throws IOException
*/
protected void ensureSourceMilestoneExists(Path source) throws IOException
protected void ensureRepositorySourceExists(Path source) throws IOException
{
}

Expand Down Expand Up @@ -708,7 +709,7 @@ else if (!host.contains("@") || !tentativeHostPath.startsWith("/"))
{
System.err.println("exitValue=" + processLauncher.exitValue());
}
return processLauncher.exitValue();
return Long.valueOf(processLauncher.exitValue());
}
}

Expand Down Expand Up @@ -774,7 +775,7 @@ else if (!host.contains("@") || !tentativeHostPath.startsWith("/"))
{
System.err.println("exitValue=" + processLauncher.exitValue());
}
return processLauncher.exitValue();
return Long.valueOf(processLauncher.exitValue());
}
}
}
Expand Down Expand Up @@ -803,6 +804,47 @@ else if (!host.contains("@") || !tentativeHostPath.startsWith("/"))
Pattern effectiveIUVersionPattern = versionIU != null
? Pattern.compile(Pattern.quote(versionIU) + ".*") : versionIUPattern != null ? Pattern.compile(versionIUPattern) : null;

Consumer<Path> repositoryMirror = (Path source) ->
{
if (host != null)
{
try
{
// Use rsync to transfer the complete contents of the remote folder to the local folder.
Path sourceRelativeTargetFolder = Paths.get(projectRoot).relativize(source);
Path normalizedAbsolutePath = ProcessLauncher.getNormalizedAbsolutePath(source);
ProcessLauncher processLauncher = new ProcessLauncher(
verbose,
"rsync",
"-avsh",
hostPrefix + hostPath + "/" + toShellPath(sourceRelativeTargetFolder) + "/",
toShellPath(normalizedAbsolutePath));

processLauncher.execute();
if (verbose)
{
processLauncher.dump();
}

if (processLauncher.exitValue() != 0)
{
if (!verbose)
{
processLauncher.fullDump();
}
else
{
System.err.println("exitValue=" + processLauncher.exitValue());
}
}
}
catch (Exception exception)
{
throw new RuntimeException(exception);
}
}
};

UpdateSiteGenerator updateSiteGenerator = new UpdateSiteGenerator(
projectLabel,
buildURL,
Expand All @@ -828,43 +870,26 @@ else if (!host.contains("@") || !tentativeHostPath.startsWith("/"))
latestVersionOnly,
summary,
summaryIUPattern,
verbose);

P2Manager p2Manager = new P2Manager(updateSiteGenerator, verbose, host == null)
verbose)
{
@Override
protected void ensureSourceMilestoneExists(Path source) throws IOException
public Path createArchive(Path repository) throws IOException
{
if (host != null)
if (!Files.isDirectory(repository.resolve("plugins")))
{
// Use rsync to transfer the complete contents of the remote folder to the local folder.
Path relativeTargetFolder = Paths.get(projectRoot).relativize(source);
Path normalizedAbsolutePath = ProcessLauncher.getNormalizedAbsolutePath(source);
ProcessLauncher processLauncher = new ProcessLauncher(
verbose,
"rsync",
"-avsh",
hostPrefix + hostPath + "/" + toShellPath(relativeTargetFolder) + "/",
toShellPath(normalizedAbsolutePath));
repositoryMirror.accept(repository);
}

processLauncher.execute();
if (verbose)
{
processLauncher.dump();
}
return super.createArchive(repository);
}
};

if (processLauncher.exitValue() != 0)
{
if (!verbose)
{
processLauncher.fullDump();
}
else
{
System.err.println("exitValue=" + processLauncher.exitValue());
}
}
}
P2Manager p2Manager = new P2Manager(updateSiteGenerator, verbose, host == null)
{
@Override
protected void ensureRepositorySourceExists(Path source) throws IOException
{
repositoryMirror.accept(source);
}
};

Expand Down Expand Up @@ -917,7 +942,7 @@ protected void ensureSourceMilestoneExists(Path source) throws IOException
System.err.println("exitValue=" + processLauncher.exitValue());
}

return processLauncher.exitValue();
return Long.valueOf(processLauncher.exitValue());
}
}

Expand Down Expand Up @@ -949,7 +974,7 @@ protected void ensureSourceMilestoneExists(Path source) throws IOException
{
System.err.println("exitValue=" + processLauncher.exitValue());
}
return processLauncher.exitValue();
return Long.valueOf(processLauncher.exitValue());
}
}

Expand Down Expand Up @@ -982,7 +1007,7 @@ protected void ensureSourceMilestoneExists(Path source) throws IOException
{
System.err.println("exitValue=" + processLauncher.exitValue());
}
return processLauncher.exitValue();
return Long.valueOf(processLauncher.exitValue());
}
}
}
Expand Down
Expand Up @@ -1100,6 +1100,15 @@ private void save(ICompositeRepository<?> repository)
compositeRepositoryApplication.addChild(childRepositoryDescriptor);
}

for (String compositeFile : new String []{ "compositeContent.jar", "compositeContent.xml", "compositeArtifacts.jar", "compositeArtifacts.xml" })
{
Path path = destination.resolve(compositeFile);
if (Files.deleteIfExists(path) && verbose)
{
System.out.println("Deleted all releases update site " + path);
}
}

IStatus status = compositeRepositoryApplication.run(new NullProgressMonitor());
if (!status.isOK())
{
Expand Down

0 comments on commit f634d76

Please sign in to comment.