Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WINDUP-241: Port Brad's Manifest Visitor to Windup 2.x
- Loading branch information
Showing
7 changed files
with
226 additions
and
73 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
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
27 changes: 11 additions & 16 deletions
27
rules/app/java/src/main/java/org/jboss/windup/rules/apps/java/model/JarManifestModel.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 |
---|---|---|
@@ -1,29 +1,24 @@ | ||
package org.jboss.windup.rules.apps.java.model; | ||
|
||
import java.util.Set; | ||
|
||
import org.jboss.windup.graph.model.ArchiveModel; | ||
import org.jboss.windup.graph.model.resource.FileModel; | ||
|
||
import com.tinkerpop.blueprints.Direction; | ||
import com.tinkerpop.frames.Adjacency; | ||
import com.tinkerpop.frames.modules.javahandler.JavaHandler; | ||
import com.tinkerpop.frames.modules.typedgraph.TypeValue; | ||
|
||
@TypeValue("JarManifestMeta") | ||
/** | ||
* Contains information from the META-INF/MANIFEST.MF file within an archive. | ||
*/ | ||
@TypeValue(JarManifestModel.TYPE) | ||
public interface JarManifestModel extends FileModel | ||
{ | ||
@Adjacency(label = "archive", direction = Direction.IN) | ||
public void setJarArchive(final JarArchiveModel archive); | ||
|
||
@Adjacency(label = "archive", direction = Direction.IN) | ||
public JarArchiveModel getJarArchive(); | ||
|
||
@JavaHandler | ||
public String getProperty(String property); | ||
public static final String TYPE = "JarManifestModel"; | ||
public static final String ARCHIVE = "archive"; | ||
|
||
@JavaHandler | ||
public void setProperty(String propertyName, String obj); | ||
@Adjacency(label = ARCHIVE, direction = Direction.IN) | ||
public void setArchive(final ArchiveModel archive); | ||
|
||
@JavaHandler | ||
public Set<String> keySet(); | ||
@Adjacency(label = ARCHIVE, direction = Direction.IN) | ||
public ArchiveModel getArchive(); | ||
} |
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
105 changes: 105 additions & 0 deletions
105
.../jboss/windup/rules/apps/java/scan/provider/DiscoverArchiveManifestFilesRuleProvider.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,105 @@ | ||
package org.jboss.windup.rules.apps.java.scan.provider; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.List; | ||
import java.util.jar.Manifest; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
import org.jboss.windup.config.GraphRewrite; | ||
import org.jboss.windup.config.RulePhase; | ||
import org.jboss.windup.config.WindupRuleProvider; | ||
import org.jboss.windup.config.operation.ruleelement.AbstractIterationOperation; | ||
import org.jboss.windup.config.query.Query; | ||
import org.jboss.windup.graph.GraphContext; | ||
import org.jboss.windup.graph.dao.ArchiveService; | ||
import org.jboss.windup.graph.model.ArchiveModel; | ||
import org.jboss.windup.graph.model.resource.FileModel; | ||
import org.jboss.windup.rules.apps.java.model.JarManifestModel; | ||
import org.jboss.windup.rules.apps.java.service.JarManifestService; | ||
import org.ocpsoft.rewrite.config.ConditionBuilder; | ||
import org.ocpsoft.rewrite.config.Configuration; | ||
import org.ocpsoft.rewrite.config.ConfigurationBuilder; | ||
import org.ocpsoft.rewrite.context.EvaluationContext; | ||
|
||
/** | ||
* Discovers MANIFEST.MF files within archives. | ||
* | ||
* @author jsightler <jesse.sightler@gmail.com> | ||
* | ||
*/ | ||
public class DiscoverArchiveManifestFilesRuleProvider extends WindupRuleProvider | ||
{ | ||
private static final Logger LOG = Logger.getLogger(DiscoverArchiveManifestFilesRuleProvider.class.getSimpleName()); | ||
|
||
@Inject | ||
private ArchiveService archiveService; | ||
|
||
@Inject | ||
private JarManifestService jarManifestService; | ||
|
||
@Override | ||
public RulePhase getPhase() | ||
{ | ||
return RulePhase.DISCOVERY; | ||
} | ||
|
||
@Override | ||
public List<Class<? extends WindupRuleProvider>> getExecuteAfter() | ||
{ | ||
return asClassList(UnzipArchivesToOutputRuleProvider.class); | ||
} | ||
|
||
@Override | ||
public Configuration getConfiguration(GraphContext context) | ||
{ | ||
ConditionBuilder archivesFound = Query.find(ArchiveModel.class); | ||
|
||
return ConfigurationBuilder.begin() | ||
.addRule() | ||
.when(archivesFound) | ||
.perform(new ExtractManifestInformationFromArchive()); | ||
} | ||
|
||
private class ExtractManifestInformationFromArchive extends AbstractIterationOperation<ArchiveModel> | ||
{ | ||
@Override | ||
public void perform(GraphRewrite event, EvaluationContext context, ArchiveModel payload) | ||
{ | ||
FileModel manifestFile = archiveService.getChildFile(payload, "META-INF/MANIFEST.MF"); | ||
if (manifestFile == null) | ||
{ | ||
// no manifest found, skip this one | ||
return; | ||
} | ||
|
||
JarManifestModel jarManifest = jarManifestService.addTypeToModel(manifestFile); | ||
jarManifest.setArchive(payload); | ||
|
||
try (InputStream is = manifestFile.asInputStream()) | ||
{ | ||
Manifest manifest = new Manifest(is); | ||
if (manifest == null || manifest.getMainAttributes().size() == 0) | ||
{ | ||
return; | ||
} | ||
|
||
for (Object key : manifest.getMainAttributes().keySet()) | ||
{ | ||
String property = StringUtils.trim(key.toString()); | ||
String propertyValue = StringUtils.trim(manifest.getMainAttributes().get(key).toString()); | ||
jarManifest.asVertex().setProperty(property, propertyValue); | ||
} | ||
} | ||
catch (IOException e) | ||
{ | ||
LOG.log(Level.WARNING, "Exception reading manifest from file: " + manifestFile.getFilePath(), e); | ||
} | ||
} | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...s/app/java/src/main/java/org/jboss/windup/rules/apps/java/service/JarManifestService.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,28 @@ | ||
package org.jboss.windup.rules.apps.java.service; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.windup.graph.GraphContext; | ||
import org.jboss.windup.graph.service.GraphService; | ||
import org.jboss.windup.rules.apps.java.model.JarManifestModel; | ||
|
||
/** | ||
* Manages the creation, querying, and deletion of {@link JarManifestModel}s. | ||
* | ||
* @author jsightler <jesse.sightler@gmail.com> | ||
* | ||
*/ | ||
public class JarManifestService extends GraphService<JarManifestModel> | ||
{ | ||
|
||
public JarManifestService() | ||
{ | ||
super(JarManifestModel.class); | ||
} | ||
|
||
@Inject | ||
public JarManifestService(GraphContext context) | ||
{ | ||
super(context, JarManifestModel.class); | ||
} | ||
} |
Oops, something went wrong.