Skip to content

Commit

Permalink
Added a dialog to write a POM with all component dependencies.
Browse files Browse the repository at this point in the history
This is meant for debugging component dependency conflicts.
  • Loading branch information
khituras committed Apr 22, 2019
1 parent 8f5c0f0 commit e97ee5b
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public static void main(String args[]) {
pipelinePath = args[0];
}
textIO = TextIoFactory.getTextIO();
if (Repositories.loadActiveRepositories().isEmpty()) {
new RepositoryAddDialog().enterInputLoop(textIO, new ArrayDeque<>());
}
IndexDialog indexDialog = new IndexDialog();
indexDialog.clearTerminal(textIO);
textIO.getTextTerminal().executeWithPropertiesPrefix(WELCOME,
Expand All @@ -58,9 +61,6 @@ public static void main(String args[]) {
"JCoRe and the individual JCoRe components is necessary. For help and " +
"pointers to the adequate documentation, please refer to the README of " +
"the pipeline modules at https://github.com/JULIELab/jcore-pipeline-modules"));
if (Repositories.loadActiveRepositories().isEmpty()) {
new RepositoryAddDialog().enterInputLoop(textIO, new ArrayDeque<>());
}
indexDialog.enterInputLoop(pipeline, textIO, new ArrayDeque<>());
} catch (GithubInformationException | MenuItemExecutionException e) {
if (e instanceof GithubInformationException || e.getCause() instanceof GithubInformationException) {
Expand Down
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import de.julielab.jcore.pipeline.builder.base.main.JcoreGithubInformationService;
import de.julielab.jcore.pipeline.builder.base.main.MetaDescription;
import de.julielab.jcore.pipeline.builder.base.main.Repositories;
import de.julielab.jcore.pipeline.builder.cli.menu.IMenuItem;
import de.julielab.jcore.pipeline.builder.cli.menu.QuitMenuItem;
import de.julielab.jcore.pipeline.builder.cli.menu.RefreshComponentRepositoryMenuItem;
import de.julielab.jcore.pipeline.builder.cli.menu.TerminalPrefixes;
import de.julielab.jcore.pipeline.builder.cli.menu.*;
import de.julielab.jcore.pipeline.builder.cli.util.MenuItemExecutionException;
import de.julielab.jcore.pipeline.builder.cli.util.StatusPrinter;
import de.julielab.jcore.pipeline.builder.cli.util.TextIOUtils;
Expand Down Expand Up @@ -54,6 +51,7 @@ private void initComponentRepository(boolean loadNew) throws GithubInformationEx
menuItems.add(new LoadPipelineDialog());
menuItems.add(new RefreshComponentRepositoryMenuItem());
menuItems.add(new RepositoryManagementDialog());
menuItems.add(new StorePomMenuItem());
menuItems.add(new QuitMenuItem());
}

Expand Down Expand Up @@ -105,6 +103,8 @@ else if (choice instanceof SavePipelineDialog) {
textIO.getTextTerminal().executeWithPropertiesPrefix(TerminalPrefixes.EMPHASIS, t -> t.print("Applying repository changes. It might take a while to fetch remote component meta data." + System.getProperty("line.separator")));
initComponentRepository(false);
clearTerminal(textIO);
} else if (choice instanceof StorePomMenuItem) {
((StorePomMenuItem)choice).execute(pipeline, textIO);
}
} catch (Exception e) {
textIO.getTextTerminal().executeWithPropertiesPrefix(TerminalPrefixes.ERROR, t -> t.print("An unexpected exception occurred: " + e.getMessage()));
Expand Down
29 changes: 29 additions & 0 deletions jcore-pipeline-builder-cli/src/main/resources/pom_template.xml
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>

0 comments on commit e97ee5b

Please sign in to comment.