-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a dialog to write a POM with all component dependencies.
This is meant for debugging component dependency conflicts.
- Loading branch information
Showing
4 changed files
with
111 additions
and
7 deletions.
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
75 changes: 75 additions & 0 deletions
75
...ilder-cli/src/main/java/de/julielab/jcore/pipeline/builder/cli/menu/StorePomMenuItem.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,75 @@ | ||
package de.julielab.jcore.pipeline.builder.cli.menu; | ||
|
||
import de.julielab.java.utilities.FileUtilities; | ||
import de.julielab.jcore.pipeline.builder.base.main.JCoReUIMAPipeline; | ||
import de.julielab.jcore.pipeline.builder.cli.main.PipelineBuilderCLI; | ||
import de.julielab.utilities.aether.MavenArtifact; | ||
import de.julielab.utilities.aether.MavenException; | ||
import de.julielab.utilities.aether.MavenProjectUtilities; | ||
import org.apache.maven.model.Model; | ||
import org.beryx.textio.TextIO; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.*; | ||
import java.nio.ByteBuffer; | ||
import java.nio.file.Path; | ||
import java.util.Objects; | ||
import java.util.stream.Stream; | ||
import java.util.stream.StreamSupport; | ||
|
||
public class StorePomMenuItem implements IMenuItem { | ||
private final static Logger log = LoggerFactory.getLogger(StorePomMenuItem.class); | ||
@Override | ||
public String getName() { | ||
return "Write a Maven POM for debugging"; | ||
} | ||
|
||
public void execute(JCoReUIMAPipeline pipeline, TextIO textIO) { | ||
final File pipelinePath = new File(PipelineBuilderCLI.pipelinePath); | ||
if (!pipelinePath.exists()) { | ||
textIO.getTextTerminal().executeWithPropertiesPrefix(TerminalPrefixes.ERROR, t -> t.print("Cannot store pom.xml because the pipeline has not been saved yet and thus, no pipeline directory exists." + System.getProperty("line.separator"))); | ||
return; | ||
} | ||
final File pomFile = Path.of(PipelineBuilderCLI.pipelinePath, "pom.xml").toFile(); | ||
textIO.getTextTerminal().print("Writing file " + pomFile + ".\n"); | ||
// write the POM template because we need a file to build a Maven model from | ||
try (final InputStream is = getClass().getResourceAsStream("/pom_template.xml");OutputStream os = new BufferedOutputStream(new FileOutputStream(pomFile))) { | ||
final ByteBuffer bb = ByteBuffer.allocate(8192); | ||
int read; | ||
while ((read = is.read(bb.array())) != -1) { | ||
bb.position(read); | ||
bb.flip(); | ||
os.write(bb.array(), 0, bb.limit()); | ||
bb.position(0); | ||
} | ||
} catch (IOException e) { | ||
textIO.getTextTerminal().executeWithPropertiesPrefix(TerminalPrefixes.ERROR, t -> t.print("Could not write the POM due to an I/O exception: " + e.getMessage() + "\n")); | ||
log.error("IOException while trying to write {}", pomFile, e); | ||
} | ||
|
||
final Stream.Builder<MavenArtifact> builder = Stream.builder(); | ||
if (pipeline.getCrDescription() != null) | ||
builder.add(pipeline.getCrDescription().getMetaDescription().getMavenArtifact()); | ||
if (pipeline.getCmDelegates() != null) | ||
pipeline.getCmDelegates().stream().filter(Objects::nonNull).map(d -> d.getMetaDescription().getMavenArtifact()).forEach(builder::add); | ||
if (pipeline.getAeDelegates() != null) | ||
pipeline.getAeDelegates().stream().filter(Objects::nonNull).map(d -> d.getMetaDescription().getMavenArtifact()).forEach(builder::add); | ||
if (pipeline.getCcDelegates() != null) | ||
pipeline.getCcDelegates().stream().filter(Objects::nonNull).map(d -> d.getMetaDescription().getMavenArtifact()).forEach(builder::add); | ||
try { | ||
final Model model = MavenProjectUtilities.addDependenciesToModel(pomFile, builder.build()); | ||
MavenProjectUtilities.writeModel(pomFile, model); | ||
} catch (MavenException e) { | ||
log.error("Exception while adding dependencies to the pipeline Maven model POM file", e); | ||
} catch (IOException e) { | ||
log.error("Exception while trying to store Maven model with dependencies to {}", pomFile, e); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getName(); | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
jcore-pipeline-builder-cli/src/main/resources/pom_template.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,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>de.julielab</groupId> | ||
<artifactId>pipeline-helper-pom</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>jar</packaging> | ||
<name>JCoRe Pipeline Helper POM</name> | ||
<description>This POM is not used by the pipeline builder but only generated by it as a helper file. It is supposed to help find library conflicts with the components of a pipeline by calling the dependency:tree or dependency:list goals using this POM file.</description> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
<configuration> | ||
<source>11</source> | ||
<target>11</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |