forked from winery/winery
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Transformation check based on rule system - Adaptation proposals - Trigger transformation from TopoMod Co-authored-by: Leonardo Frioli <[email protected]> Signed-off-by: Michael Wurster <[email protected]>
- Loading branch information
Showing
37 changed files
with
2,169 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ Michael Wurster <[email protected]> | |
Latife Sen <[email protected]> | ||
Ana Cristina Franco da Silva <[email protected]> | ||
Pascal Hirmer <[email protected]> <[email protected]> | ||
Leonardo Frioli <[email protected]> | ||
Dominik Voigt <[email protected]> | ||
Ghareeb Falazi <[email protected]> | ||
Björn Müller <[email protected]> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
org.eclipse.winery.edmm/src/main/java/org/eclipse/winery/edmm/TransformationManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache Software License 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*******************************************************************************/ | ||
package org.eclipse.winery.edmm; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.winery.edmm.plugins.PluginManager; | ||
import org.eclipse.winery.edmm.utils.ZipUtility; | ||
|
||
import io.github.edmm.core.parser.EntityGraph; | ||
import io.github.edmm.core.plugin.PluginService; | ||
import io.github.edmm.core.transformation.TransformationContext; | ||
import io.github.edmm.core.transformation.TransformationService; | ||
import io.github.edmm.model.DeploymentModel; | ||
|
||
public class TransformationManager { | ||
|
||
public File transform(EntityGraph entityGraph, String target, String wineryRepository) throws Exception { | ||
PluginService pluginService = PluginManager.getInstance() | ||
.getPluginService(); | ||
TransformationService transformationService = new TransformationService(pluginService); | ||
|
||
// getting the model from the graph | ||
DeploymentModel deploymentModel = new DeploymentModel(UUID.randomUUID().toString(), entityGraph); | ||
|
||
// the paths of the artifacts or operation files start from the root directory | ||
File sourceDirectory = Paths.get(wineryRepository).toFile(); | ||
File targetDirectory = Files.createTempDirectory(target + "-").toFile(); | ||
|
||
TransformationContext transformationContext = transformationService.createContext(deploymentModel, target, sourceDirectory, targetDirectory); | ||
transformationService.start(transformationContext); | ||
// throws an exception if the transformation wasn't successful | ||
transformationContext.throwExceptionIfErrorState(); | ||
|
||
Path zipPath = Paths.get(System.getProperty("java.io.tmpdir")).resolve(target + ".zip"); | ||
ZipUtility.pack(targetDirectory.toPath(), zipPath); | ||
|
||
return zipPath.toFile(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
org.eclipse.winery.edmm/src/main/java/org/eclipse/winery/edmm/plugins/PluginManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache Software License 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.winery.edmm.plugins; | ||
|
||
import java.io.InputStream; | ||
import java.lang.reflect.Constructor; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
|
||
import io.github.edmm.core.plugin.PluginService; | ||
import io.github.edmm.core.plugin.TransformationPlugin; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
public class PluginManager { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(PluginManager.class); | ||
private static PluginManager instance; | ||
|
||
private final List<TransformationPlugin<?>> pluginsList = new ArrayList<>(); | ||
|
||
private PluginManager() { | ||
initPlugins(); | ||
} | ||
|
||
public static PluginManager getInstance() { | ||
if (instance == null) { | ||
instance = new PluginManager(); | ||
} | ||
return instance; | ||
} | ||
|
||
public PluginService getPluginService() { | ||
return new PluginService(pluginsList, new ArrayList<>()); | ||
} | ||
|
||
/** | ||
* Init the plugins lists with the plugins specified in the pluginContext.xml file in the transformation-framework | ||
* package | ||
*/ | ||
private void initPlugins() { | ||
for (String classpath : getPluginsClassPaths()) { | ||
TransformationPlugin<?> plugin; | ||
// the plugin are initialized by reflection | ||
try { | ||
Class<?> pluginClass = Class.forName(classpath); | ||
Constructor<?> constructor = pluginClass.getConstructor(); | ||
plugin = (TransformationPlugin<?>) constructor.newInstance(); | ||
pluginsList.add(plugin); | ||
} catch (Exception e) { | ||
// just the single plugin won't work | ||
LOGGER.error("Plugin" + classpath + "initialization failed", e); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Read the pluginContext configuration file | ||
* | ||
* @return a list containing the plugins classpaths | ||
*/ | ||
private List<String> getPluginsClassPaths() { | ||
List<String> pluginsClassPaths = new ArrayList<>(); | ||
Document xmlPluginConfigDocument; | ||
|
||
// opening the file in the edmm.core package | ||
try { | ||
InputStream pluginsInputStream = this.getClass() | ||
.getClassLoader() | ||
.getResourceAsStream("pluginContext.xml"); | ||
|
||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); | ||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); | ||
xmlPluginConfigDocument = documentBuilder.parse(pluginsInputStream); | ||
} catch (Exception e) { | ||
LOGGER.error("Plugin file reading failed", e); | ||
// returns an empty list, no plugins will be initialized | ||
return pluginsClassPaths; | ||
} | ||
|
||
// the plugins are listed with the tag name 'bean' | ||
NodeList pluginsNodeList = xmlPluginConfigDocument.getElementsByTagName("bean"); | ||
for (int i = 0; i < pluginsNodeList.getLength(); i++) { | ||
Node plugin = pluginsNodeList.item(i); | ||
String classpath = plugin.getAttributes().getNamedItem("class").getNodeValue(); | ||
pluginsClassPaths.add(classpath); | ||
} | ||
|
||
return pluginsClassPaths; | ||
} | ||
|
||
public List<TransformationPlugin<?>> getPluginsList() { | ||
return pluginsList; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
org.eclipse.winery.edmm/src/main/java/org/eclipse/winery/edmm/utils/ZipUtility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache Software License 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*******************************************************************************/ | ||
package org.eclipse.winery.edmm.utils; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipInputStream; | ||
|
||
import io.github.edmm.utils.Compress; | ||
|
||
public class ZipUtility { | ||
|
||
public static void pack(Path sourcePath, Path destPath) { | ||
Compress.zip(sourcePath, destPath); | ||
} | ||
|
||
/** | ||
* @param zipFilePath the Path of the zip file to unpack | ||
* @param destDirPath the Path of the directory where we want the unzipped files, if the direcory exists it will be | ||
* overwritten | ||
* @return it return destDirPath | ||
*/ | ||
public static Path unpack(Path zipFilePath, Path destDirPath) throws IOException { | ||
if (Files.exists(destDirPath)) { | ||
Files.delete(destDirPath); | ||
} | ||
Files.createDirectory(destDirPath); | ||
|
||
ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(zipFilePath.toFile())); | ||
|
||
ZipEntry zipEntry = zipInputStream.getNextEntry(); | ||
while (zipEntry != null) { | ||
|
||
Path newFile = destDirPath.resolve(zipEntry.getName()); | ||
Files.createDirectories(newFile.getParent()); | ||
Files.copy(zipInputStream, newFile); | ||
zipEntry = zipInputStream.getNextEntry(); | ||
} | ||
zipInputStream.closeEntry(); | ||
zipInputStream.close(); | ||
|
||
return destDirPath; | ||
} | ||
} |
Oops, something went wrong.