2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.global_tests;
24 import java.io.IOException;
25 import java.nio.file.DirectoryStream;
26 import java.nio.file.Files;
27 import java.nio.file.Path;
28 import java.nio.file.Paths;
29 import java.util.Iterator;
31 import org.jboss.shrinkwrap.api.Archive;
32 import org.jboss.shrinkwrap.api.ShrinkWrap;
33 import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
34 import org.jboss.shrinkwrap.api.spec.JavaArchive;
35 import org.jboss.shrinkwrap.api.spec.WebArchive;
37 public class ArquillianPackagerForITCases {
39 public static Archive<?> createPackageFromExistingOne(String path, String globPattern, String newPackageName) {
40 Path dir = Paths.get(path);
42 try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, globPattern)) {
43 Iterator<Path> it = stream.iterator();
46 if (newPackageName.endsWith(".war")) {
47 File archive = it.next().toFile();
48 WebArchive webArchive = ShrinkWrap.create(WebArchive.class, newPackageName);
49 webArchive.merge((ShrinkWrap.createFromZipFile(WebArchive.class, archive)));
51 } else if (newPackageName.endsWith(".jar")) {
52 File archive = it.next().toFile();
53 JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, newPackageName);
54 javaArchive.merge((ShrinkWrap.createFromZipFile(JavaArchive.class, archive)));
56 } else if (newPackageName.endsWith(".ear")) {
57 File archive = it.next().toFile();
58 EnterpriseArchive earArchive = ShrinkWrap.create(EnterpriseArchive.class, newPackageName);
59 earArchive.merge((ShrinkWrap.createFromZipFile(EnterpriseArchive.class, archive)));
69 } catch (IOException e) {