Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 82273 invoked from network); 2 Sep 2009 14:36:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 2 Sep 2009 14:36:09 -0000 Received: (qmail 43792 invoked by uid 500); 2 Sep 2009 14:36:09 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 43712 invoked by uid 500); 2 Sep 2009 14:36:09 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 43703 invoked by uid 99); 2 Sep 2009 14:36:09 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Sep 2009 14:36:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Sep 2009 14:36:07 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 695ED2388876; Wed, 2 Sep 2009 14:35:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r810526 - /cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ClassLoaderSwitcher.java Date: Wed, 02 Sep 2009 14:35:47 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090902143547.695ED2388876@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dkulp Date: Wed Sep 2 14:35:46 2009 New Revision: 810526 URL: http://svn.apache.org/viewvc?rev=810526&view=rev Log: Set eol-style Modified: cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ClassLoaderSwitcher.java (contents, props changed) Modified: cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ClassLoaderSwitcher.java URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ClassLoaderSwitcher.java?rev=810526&r1=810525&r2=810526&view=diff ============================================================================== --- cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ClassLoaderSwitcher.java (original) +++ cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ClassLoaderSwitcher.java Wed Sep 2 14:35:46 2009 @@ -1,122 +1,122 @@ -/** - * 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_plugin; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.cxf.helpers.CastUtils; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.plugin.logging.Log; -import org.apache.maven.project.MavenProject; - -/** - * Manages switching to the classloader needed for creating the java sources and restoring the old classloader - * when finished - */ -public class ClassLoaderSwitcher { - - private Log log; - private String origClassPath; - private Map origProps; - private ClassLoader origContextClassloader; - - public ClassLoaderSwitcher(Log log) { - this.log = log; - } - - /** - * Create and set the classloader that is needed for creating the java sources from wsdl - * - * @param project - * @param useCompileClasspath - * @param classesDir - */ - public void switchClassLoader(MavenProject project, boolean useCompileClasspath, File classesDir) { - List urlList = new ArrayList(); - StringBuffer buf = new StringBuffer(); - - try { - urlList.add(classesDir.toURI().toURL()); - if (!useCompileClasspath) { - urlList.add(new File(project.getBuild().getOutputDirectory()).toURI().toURL()); - } - } catch (MalformedURLException e) { - // ignore - } - - buf.append(classesDir.getAbsolutePath()); - buf.append(File.pathSeparatorChar); - if (!useCompileClasspath) { - buf.append(project.getBuild().getOutputDirectory()); - buf.append(File.pathSeparatorChar); - } - List artifacts = useCompileClasspath ? project.getCompileArtifacts() : project.getTestArtifacts(); - for (Artifact a : CastUtils.cast(artifacts, Artifact.class)) { - try { - if (a.getFile() != null && a.getFile().exists()) { - urlList.add(a.getFile().toURI().toURL()); - buf.append(a.getFile().getAbsolutePath()); - buf.append(File.pathSeparatorChar); - // System.out.println(" " + - // a.getFile().getAbsolutePath()); - } - } catch (MalformedURLException e) { - // ignore - } - } - - origContextClassloader = Thread.currentThread().getContextClassLoader(); - URLClassLoader loader = new URLClassLoader(urlList.toArray(new URL[urlList.size()]), - origContextClassloader); - String newCp = buf.toString(); - - log.debug("Classpath: " + urlList.toString()); - - origProps = new HashMap(System.getProperties()); - - origClassPath = System.getProperty("java.class.path"); - - Thread.currentThread().setContextClassLoader(loader); - System.setProperty("java.class.path", newCp); - } - - /** - * Restore the old classloader - */ - public void restoreClassLoader() { - Thread.currentThread().setContextClassLoader(origContextClassloader); - System.setProperty("java.class.path", origClassPath); - - Map newProps = new HashMap(System.getProperties()); - for (Object o : newProps.keySet()) { - if (!origProps.containsKey(o)) { - System.clearProperty(o.toString()); - } - } - System.getProperties().putAll(origProps); - } -} +/** + * 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_plugin; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.cxf.helpers.CastUtils; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; + +/** + * Manages switching to the classloader needed for creating the java sources and restoring the old classloader + * when finished + */ +public class ClassLoaderSwitcher { + + private Log log; + private String origClassPath; + private Map origProps; + private ClassLoader origContextClassloader; + + public ClassLoaderSwitcher(Log log) { + this.log = log; + } + + /** + * Create and set the classloader that is needed for creating the java sources from wsdl + * + * @param project + * @param useCompileClasspath + * @param classesDir + */ + public void switchClassLoader(MavenProject project, boolean useCompileClasspath, File classesDir) { + List urlList = new ArrayList(); + StringBuffer buf = new StringBuffer(); + + try { + urlList.add(classesDir.toURI().toURL()); + if (!useCompileClasspath) { + urlList.add(new File(project.getBuild().getOutputDirectory()).toURI().toURL()); + } + } catch (MalformedURLException e) { + // ignore + } + + buf.append(classesDir.getAbsolutePath()); + buf.append(File.pathSeparatorChar); + if (!useCompileClasspath) { + buf.append(project.getBuild().getOutputDirectory()); + buf.append(File.pathSeparatorChar); + } + List artifacts = useCompileClasspath ? project.getCompileArtifacts() : project.getTestArtifacts(); + for (Artifact a : CastUtils.cast(artifacts, Artifact.class)) { + try { + if (a.getFile() != null && a.getFile().exists()) { + urlList.add(a.getFile().toURI().toURL()); + buf.append(a.getFile().getAbsolutePath()); + buf.append(File.pathSeparatorChar); + // System.out.println(" " + + // a.getFile().getAbsolutePath()); + } + } catch (MalformedURLException e) { + // ignore + } + } + + origContextClassloader = Thread.currentThread().getContextClassLoader(); + URLClassLoader loader = new URLClassLoader(urlList.toArray(new URL[urlList.size()]), + origContextClassloader); + String newCp = buf.toString(); + + log.debug("Classpath: " + urlList.toString()); + + origProps = new HashMap(System.getProperties()); + + origClassPath = System.getProperty("java.class.path"); + + Thread.currentThread().setContextClassLoader(loader); + System.setProperty("java.class.path", newCp); + } + + /** + * Restore the old classloader + */ + public void restoreClassLoader() { + Thread.currentThread().setContextClassLoader(origContextClassloader); + System.setProperty("java.class.path", origClassPath); + + Map newProps = new HashMap(System.getProperties()); + for (Object o : newProps.keySet()) { + if (!origProps.containsKey(o)) { + System.clearProperty(o.toString()); + } + } + System.getProperties().putAll(origProps); + } +} Propchange: cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ClassLoaderSwitcher.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ClassLoaderSwitcher.java ------------------------------------------------------------------------------ svn:keywords = Rev Date