Skip to content
Permalink
Browse files
Copy some buildtools stuff
git-svn-id: https://svn.apache.org/repos/asf/cxf/build-utils/trunk@906536 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
dkulp committed Feb 4, 2010
0 parents commit d632512a1914f907bfeb22f364d096e8748ac324
Showing 20 changed files with 2,600 additions and 0 deletions.
@@ -0,0 +1,80 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->
<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/maven-v4_0_0.xsd">
<parent>
<groupId>org.apache.cxf.build-utils</groupId>
<artifactId>cxf-build-utils</artifactId>
<version>2.3.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.cxf.build-utils</groupId>
<artifactId>cxf-buildtools</artifactId>
<name>Apache CXF Buildtools</name>
<url>http://cxf.apache.org</url>
<packaging>jar</packaging>

<properties>
<maven.test.skip>true</maven.test.skip>
</properties>

<dependencies>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>1.4.4</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0.7</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>2.0.7</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0.7</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.1</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>pmd</groupId>
<artifactId>pmd</artifactId>
<version>4.2</version>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,129 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.cxf.maven;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;

import org.apache.maven.plugins.shade.resource.ResourceTransformer;
import org.jdom.Content;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

public class CXFAllTransformer implements ResourceTransformer {

byte buffer[] = new byte[1024];
Map<String, ByteArrayOutputStream> extensions
= new LinkedHashMap<String, ByteArrayOutputStream>();
String lastResource;

public CXFAllTransformer() {
super();
}

public boolean canTransformResource(String r) {
if (r.startsWith("META-INF/cxf/cxf-extension-")
&& r.endsWith(".xml")) {
lastResource = r;
return true;
}
return false;
}
public boolean hasTransformedResource() {
return !extensions.isEmpty();
}

public void processResource(InputStream is) throws IOException {
ByteArrayOutputStream bout = new ByteArrayOutputStream(1024);
int i = is.read(buffer);
while (i != -1) {
bout.write(buffer, 0, i);
i = is.read(buffer);
}
extensions.put(lastResource, bout);
}
public void modifyOutputStream(JarOutputStream jos) throws IOException {
List<String> imps = new ArrayList<String>(extensions.keySet());
for (Map.Entry<String, ByteArrayOutputStream> ent : extensions.entrySet()) {
jos.putNextEntry(new JarEntry(ent.getKey()));
ent.getValue().writeTo(jos);
try {
Document r = new SAXBuilder()
.build(new ByteArrayInputStream(ent.getValue().toByteArray()));

Element root = r.getRootElement();
for (Iterator itr = root.getChildren().iterator(); itr.hasNext();) {
Content n = (Content)itr.next();
if (n instanceof Element) {
Element e = (Element)n;
if ("import".equals(e.getName())
&& "http://www.springframework.org/schema/beans".equals(e.getNamespaceURI())) {

//remove stuff that is imported from other extensions to
//keep them from being loaded twice. (it's not an issue
//to load them twice, there just is a performance
//penalty in doing so
String loc = e.getAttributeValue("resource");
if (loc.startsWith("classpath:META-INF/cxf/cxf")) {

loc = loc.substring(10);
imps.remove(loc);
}
}
}
}
} catch (JDOMException e) {
throw new RuntimeException(e);
}
}

if (imps.size() > 0) {
jos.putNextEntry(new JarEntry("META-INF/cxf/cxf-all.xml"));
Writer writer = new OutputStreamWriter(jos, "UTF-8");
writer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
writer.append("<beans xmlns=\"http://www.springframework.org/schema/beans\"\n");
writer.append(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
writer.append(" xsi:schemaLocation=\"");
writer.append("http://www.springframework.org/schema/beans ");
writer.append("http://www.springframework.org/schema/beans/spring-beans.xsd\">\n");
writer.append(" <import resource=\"classpath:META-INF/cxf/cxf.xml\"/>\n");
for (String res : imps) {
writer.append(" <import resource=\"classpath:");
writer.append(res);
writer.append("\"/>\n");
}
writer.append("</beans>");
writer.flush();
}
}
}

@@ -0,0 +1,92 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.cxf.maven;

import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;

import org.apache.maven.plugins.shade.resource.ResourceTransformer;
import org.jdom.Content;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

public class PluginTransformer implements ResourceTransformer {
public static final String XSI_NS = "http://www.w3.org/2001/XMLSchema-instance";

String resource;
Document doc;

public PluginTransformer() {
super();
}

public boolean canTransformResource(String r) {
r = r.toLowerCase();

if (resource != null && resource.toLowerCase().equals(r)) {
return true;
}

return false;
}

public void processResource(InputStream is) throws IOException {
Document r;
try {
r = new SAXBuilder().build(is);
} catch (JDOMException e) {
throw new RuntimeException(e);
}

if (doc == null) {
doc = r;

Element el = doc.getRootElement();
el.setAttribute("name", "default");
el.setAttribute("provider", "cxf.apache.org");
} else {
Element root = r.getRootElement();

for (Iterator itr = root.getChildren().iterator(); itr.hasNext();) {
Content n = (Content)itr.next();
itr.remove();

doc.getRootElement().addContent(n);
}
}
}

public boolean hasTransformedResource() {
return doc != null;
}

public void modifyOutputStream(JarOutputStream jos) throws IOException {
jos.putNextEntry(new JarEntry(resource));

new XMLOutputter(Format.getPrettyFormat()).output(doc, jos);
doc = null;
}
}
@@ -0,0 +1,79 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.cxf.pmd;

import java.util.List;

import net.sourceforge.pmd.AbstractJavaRule;
import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.ast.ASTAdditiveExpression;
import net.sourceforge.pmd.ast.ASTAllocationExpression;
import net.sourceforge.pmd.ast.ASTArgumentList;
import net.sourceforge.pmd.ast.ASTArrayDimsAndInits;
import net.sourceforge.pmd.ast.ASTClassOrInterfaceType;
import net.sourceforge.pmd.ast.ASTExpression;
import net.sourceforge.pmd.ast.ASTName;
import net.sourceforge.pmd.ast.Node;
import net.sourceforge.pmd.ast.SimpleNode;
import net.sourceforge.pmd.symboltable.NameDeclaration;
import net.sourceforge.pmd.symboltable.VariableNameDeclaration;
import net.sourceforge.pmd.typeresolution.TypeHelper;

/**
* Look for new String(byte[]) or new String(byte[], start, end)
* and complain.
*/
public class UnsafeStringConstructorRule extends AbstractJavaRule {

/** {@inheritDoc} */
@Override
public Object visit(ASTAllocationExpression node, Object data) {
if (!(node.jjtGetChild(0) instanceof ASTClassOrInterfaceType)) {
return data;
}

if (!TypeHelper.isA((ASTClassOrInterfaceType)node.jjtGetChild(0), String.class)) {
return data;
}

ASTArgumentList arglist = node.getFirstChildOfType(ASTArgumentList.class);
if (arglist == null) { // unlikely
return data;
}

// one of the two possibilities ...
if (arglist.jjtGetNumChildren() == 1 || arglist.jjtGetNumChildren() == 3) {
ASTExpression firstArgExpr = arglist.getFirstChildOfType(ASTExpression.class);
Class<?> exprType = firstArgExpr.getType();
// pmd reports the type as byte, not byte[]. But since
// there is no such thing as new String(byte), it seems
// safe enough to take that as good enough.
if (exprType != null) {
if (exprType == Byte.TYPE ||
(exprType.isArray() && exprType.getComponentType() == Byte.TYPE)) {
addViolation(data, node);
}
}
}
return data;

}

}

0 comments on commit d632512

Please sign in to comment.