Skip to content

Commit

Permalink
v3.0.5.6, pom processor - remove api_classic dependency from POM
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed May 6, 2019
1 parent d73aab4 commit c3c4bf6
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 14 deletions.
64 changes: 50 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.klinec</groupId>
<version>3.0.5.5</version>
<version>3.0.5.6</version>
<packaging>jar</packaging>
<url>http://maven.apache.org</url>

Expand Down Expand Up @@ -224,33 +224,48 @@
</execution>
</executions>
</plugin>
<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-noverify</argLine>
</configuration>
</plugin>
<configuration>
<argLine>-noverify</argLine>
</configuration>
</plugin>
<!-- patch -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<id>cardApi</id>
<phase>process-classes</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.licel.jcardsim.utils.JavaCardApiProcessor</mainClass>
<arguments>
<argument>${project.build.directory}/classes</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>pom</id>
<phase>verify</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.licel.jcardsim.utils.PomProcessor</mainClass>
<arguments>
<argument>${project.build.directory}</argument>
</arguments>
</configuration>
</execution>
</executions>
<configuration>
<mainClass>com.licel.jcardsim.utils.JavaCardApiProcessor</mainClass>
<arguments>
<argument>${project.build.directory}/classes</argument>
</arguments>
</configuration>

</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -269,6 +284,7 @@
<artifactId>maven-shade-plugin</artifactId>
<version>1.7</version>
<configuration>
<keepDependenciesWithProvidedScope>false</keepDependenciesWithProvidedScope>
<minimizeJar>true</minimizeJar>
<relocations>
<relocation>
Expand All @@ -280,6 +296,12 @@
<includes>
<include>org.bouncycastle:*</include>
</includes>
<excludes>
<exclude>oracle.javacard:*</exclude>
<exclude>oracle.javacard:*:*:*</exclude>
<exclude>*:api_classic</exclude>
<exclude>oracle.javacard:api_classic</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
Expand All @@ -300,11 +322,18 @@
<goal>shade</goal>
</goals>
<configuration>
<keepDependenciesWithProvidedScope>false</keepDependenciesWithProvidedScope>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>org.bouncycastle:*</include>
</includes>
<excludes>
<exclude>oracle.javacard:*</exclude>
<exclude>oracle.javacard:*:*:*</exclude>
<exclude>*:api_classic</exclude>
<exclude>oracle.javacard:api_classic</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
Expand All @@ -325,10 +354,17 @@
<goal>shade</goal>
</goals>
<configuration>
<keepDependenciesWithProvidedScope>false</keepDependenciesWithProvidedScope>
<artifactSet>
<includes>
<include>org.bouncycastle:*</include>
</includes>
<excludes>
<exclude>oracle.javacard:*</exclude>
<exclude>oracle.javacard:*:*:*</exclude>
<exclude>*:api_classic</exclude>
<exclude>oracle.javacard:api_classic</exclude>
</excludes>
</artifactSet>
<minimizeJar>true</minimizeJar>
<shadedArtifactAttached>true</shadedArtifactAttached>
Expand Down Expand Up @@ -418,7 +454,7 @@

<echo>Testing shaded JAR: ${project.artifactId}-${project.version}-android.jar</echo>
<junit fork="yes" forkmode="once" haltonfailure="yes" printsummary="true">
<jvmarg value="-noverify"/>
<jvmarg value="-noverify"/>
<classpath>
<path refid="testClasspath" />
<pathelement location="${ant.build.dir}/bin" />
Expand Down
141 changes: 141 additions & 0 deletions src/main/java/com/licel/jcardsim/utils/PomProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
* Copyright 2015 Licel Corporation.
*
* 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.
*/
package com.licel.jcardsim.utils;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.File;

/**
* Injects jCardSim’s code into Java Card Api Reference Classes
*/
public class PomProcessor {

public static void main(String[] args) throws Exception {
if (args.length == 0){
throw new IllegalArgumentException("Build directory is required");
}

File buildDir = new File(args[0]);
if (!buildDir.exists() || !buildDir.isDirectory()) {
throw new RuntimeException("Invalid directory: " + buildDir);
}

final File depPom = new File(buildDir, "dependency-reduced-pom.xml");
if (!depPom.exists()){
System.err.println("POM not found: " + depPom.getAbsolutePath());
return;
}

DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder;

try {
dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(depPom);

deleteElement(doc);

//write the updated document to file or console
doc.getDocumentElement().normalize();
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(depPom);
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(source, result);
System.out.println("XML file updated successfully");

} catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace(System.err);
}
}

private static void deleteElement(Document doc) {
NodeList projects = doc.getElementsByTagName("project");
if (projects.getLength() < 1){
System.err.println("Invalid number of project elements");
return;
}

final Node project = projects.item(0);
if (project.getNodeType() != Node.ELEMENT_NODE){
System.err.println("Invalid project node type");
return;
}

Element elProject = (Element) project;
final NodeList dependencies = elProject.getElementsByTagName("dependencies");
if (dependencies.getLength() < 1){
System.err.println("Invalid num of dependencies");
return;
}

boolean found = false;
int depIdx = 0;
for(depIdx = 0; depIdx < dependencies.getLength(); depIdx++){
if (dependencies.item(depIdx).getParentNode() == elProject){
found = true;
break;
}
}

if (!found){
System.err.println("Project.dependencies not found");
return;
}

final Node nDeps = dependencies.item(depIdx);
if (nDeps.getNodeType() != Node.ELEMENT_NODE){
System.err.println("Invalid dependencies node type");
return;
}

Element elDeps = (Element) nDeps;
final NodeList depsNodeList = elDeps.getElementsByTagName("dependency");
if (depsNodeList.getLength() < 1){
System.err.println("No deps found");
return;
}

for(int i=0; i < depsNodeList.getLength(); i++){
final Element elDep = (Element)depsNodeList.item(i);
final NodeList nArtifacts = elDep.getElementsByTagName("artifactId");
if (nArtifacts.getLength() == 0){
continue;
}

final Element elArtifact = (Element)nArtifacts.item(0);
final Node alChild = elArtifact.getFirstChild();
if (alChild.getNodeType() == Node.TEXT_NODE && alChild.getNodeValue().equalsIgnoreCase("api_classic")){
System.err.println("api_classic found in dependencies");
elDeps.removeChild(elDep);
return;
}
}
}
}

0 comments on commit c3c4bf6

Please sign in to comment.