<commit_before>/*
 * Copyright 2011 <a href="mailto:<EMAIL>"><NAME>, III</a>
 *
 * 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 org.ocpsoft.rewrite.test;

import java.io.File;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.runner.RunWith;
import org.ocpsoft.rewrite.mock.MockBinding;

import com.sun.el.ExpressionFactoryImpl;

/**
 * @author <a href="mailto:<EMAIL>"><NAME>, III</a>
 * 
 */
@RunWith(Arquillian.class)
public class RewriteTest extends RewriteTestBase
{
   @Deployment(testable = false)
   public static WebArchive getDeployment()
   {
      WebArchive archive = getDeploymentNoWebXml();
      if(isJetty()) {
         archive.setWebXML("jetty-web.xml");
      }
      return archive;
   }

   public static WebArchive getDeploymentNoWebXml()
   {

      WebArchive archive = ShrinkWrap
               .create(WebArchive.class, "rewrite-test.war")
               .addPackages(true, MockBinding.class.getPackage())
               .addAsLibraries(resolveDependencies("org.ocpsoft.logging:logging-api:1.0.1.Final"))
               .addAsLibraries(getRewriteArchive())
               .addAsLibraries(getCurrentArchive());

      // Jetty specific stuff
      if(isJetty()) {
         
          archive.addAsLibraries(resolveDependencies("org.jboss.weld.servlet:weld-servlet:1.1.4.Final"));
         
          /*
          * Set the EL implementation
          */
         archive.addAsLibraries(resolveDependencies("org.glassfish.web:el-impl:jar:2.2"));
         archive.add(new StringAsset("com.sun.el.ExpressionFactoryImpl"),
                  "/WEB-INF/classes/META-INF/services/javax.el.ExpressionFactory");
         
          /*
          * Set up container configuration
          */
          archive.addAsWebInfResource(new StringAsset("<beans/>"), "beans.xml");
          archive.addAsWebInfResource("jetty-env.xml", "jetty-env.xml");
          archive.addAsWebInfResource("jetty-log4j.xml", "log4j.xml");
          
      }
      
      System.out.println(archive.toString(true));
      
      return archive;
   }
   
   protected static boolean isJetty() {
      ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
      try {
         classLoader.loadClass("org.jboss.arquillian.container.jetty.embedded_7.JettyEmbeddedContainer");
         return true;
      }
      catch (ClassNotFoundException e) {
         return false;
      }
   }

   protected static JavaArchive getCurrentArchive()
   {
      File classes = new File("target/classes/org");
      File metaInf = new File("target/classes/META-INF");

      JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "rewrite-current-module.jar");

      if (classes.exists())
         archive.addAsResource(classes);
      if (metaInf.exists())
         archive.addAsResource(metaInf);
      
      return archive.addAsResource(new StringAsset("placeholder"), "README");
   }

   protected static JavaArchive getRewriteArchive()
   {
      JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "rewrite-servlet.jar")

               .addAsResource(new File("../api/target/classes/org"))
               .addAsResource(new File("../api-el/target/classes/org"))
               .addAsResource(new File("../api-el/target/classes/META-INF"))
               .addAsResource(new File("../impl-config/target/classes/org"))
               .addAsResource(new File("../api-servlet/target/classes/org"))
               .addAsResource(new File("../impl-servlet/target/classes/org"))
               .addAsResource(new File("../impl-servlet/target/classes/META-INF"));

      return archive;
   }
}
<commit_msg>Some first steps for getting the tests run with Jetty again<commit_after>/*
 * Copyright 2011 <a href="mailto:<EMAIL>"><NAME>, III</a>
 *
 * 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 org.ocpsoft.rewrite.test;

import java.io.File;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.runner.RunWith;
import org.ocpsoft.rewrite.mock.MockBinding;

/**
 * @author <a href="mailto:<EMAIL>"><NAME>, III</a>
 * 
 */
@RunWith(Arquillian.class)
public class RewriteTest extends RewriteTestBase
{
   @Deployment(testable = false)
   public static WebArchive getDeployment()
   {
      WebArchive archive = getDeploymentNoWebXml();
      if(isJetty()) {
         archive.setWebXML("jetty-web.xml");
      }
      return archive;
   }

   public static WebArchive getDeploymentNoWebXml()
   {

      WebArchive archive = ShrinkWrap
               .create(WebArchive.class, "rewrite-test.war")
               .addPackages(true, MockBinding.class.getPackage())
               .addAsLibraries(resolveDependencies("org.ocpsoft.logging:logging-api:1.0.1.Final"))
               .addAsLibraries(getRewriteArchive())
               .addAsLibraries(getCurrentArchive());

      // Jetty specific stuff
      if(isJetty()) {
         
          archive.addAsLibraries(resolveDependencies("org.jboss.weld.servlet:weld-servlet:1.1.4.Final"));
         
          /*
          * Set the EL implementation
          */
         archive.addAsLibraries(resolveDependencies("org.glassfish.web:el-impl:jar:2.2"));
         archive.add(new StringAsset("com.sun.el.ExpressionFactoryImpl"),
                  "/WEB-INF/classes/META-INF/services/javax.el.ExpressionFactory");
         
          /*
          * Set up container configuration
          */
          archive.addAsWebInfResource(new StringAsset("<beans/>"), "beans.xml");
          archive.addAsWebInfResource("jetty-env.xml", "jetty-env.xml");
          archive.addAsWebInfResource("jetty-log4j.xml", "log4j.xml");
          
      }
      
      System.out.println(archive.toString(true));
      
      return archive;
   }
   
   protected static boolean isJetty() {
      ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
      try {
         classLoader.loadClass("org.jboss.arquillian.container.jetty.embedded_7.JettyEmbeddedContainer");
         return true;
      }
      catch (ClassNotFoundException e) {
         return false;
      }
   }

   protected static JavaArchive getCurrentArchive()
   {
      File classes = new File("target/classes/org");
      File metaInf = new File("target/classes/META-INF");

      JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "rewrite-current-module.jar");

      if (classes.exists())
         archive.addAsResource(classes);
      if (metaInf.exists())
         archive.addAsResource(metaInf);
      
      return archive.addAsResource(new StringAsset("placeholder"), "README");
   }

   protected static JavaArchive getRewriteArchive()
   {
      JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "rewrite-servlet.jar")

               .addAsResource(new File("../api/target/classes/org"))
               .addAsResource(new File("../api-el/target/classes/org"))
               .addAsResource(new File("../api-el/target/classes/META-INF"))
               .addAsResource(new File("../impl-config/target/classes/org"))
               .addAsResource(new File("../api-servlet/target/classes/org"))
               .addAsResource(new File("../impl-servlet/target/classes/org"))
               .addAsResource(new File("../impl-servlet/target/classes/META-INF"));

      return archive;
   }
}

{'fraction_non_alphanumeric': 0.12394814646349785, 'fraction_numerical': 0.004321128041846714, 'mean_word_length': 2.792583009918068, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6961750', 'n_tokens_mistral': 2669, 'n_tokens_neox': 2534, 'n_words': 480}