2020-03-23 15:35:58 +01:00
|
|
|
/*
|
|
|
|
|
* MIT License
|
2014-07-13 09:47:14 +02:00
|
|
|
*
|
2020-03-23 15:35:58 +01:00
|
|
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
2014-07-13 09:47:14 +02:00
|
|
|
*
|
2020-03-23 15:35:58 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2014-07-13 09:47:14 +02:00
|
|
|
*
|
2020-03-23 15:35:58 +01:00
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
2014-07-13 09:47:14 +02:00
|
|
|
*
|
2020-03-23 15:35:58 +01:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
2014-07-13 09:47:14 +02:00
|
|
|
*/
|
2020-03-23 15:35:58 +01:00
|
|
|
|
2014-07-13 09:47:14 +02:00
|
|
|
package sonia.scm.plugin;
|
|
|
|
|
|
|
|
|
|
//~--- non-JDK imports --------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
import com.google.common.base.Function;
|
2019-01-10 12:09:07 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
2014-07-13 09:47:14 +02:00
|
|
|
|
|
|
|
|
//~--- JDK imports ------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
|
2014-07-13 13:47:35 +02:00
|
|
|
import java.util.Set;
|
2014-07-13 09:47:14 +02:00
|
|
|
|
|
|
|
|
/**
|
2014-10-10 21:26:47 +02:00
|
|
|
* The ExplodedSmp object represents an extracted SCM-Manager plugin. The object
|
|
|
|
|
* contains the path to the plugin directory and loads the plugin descriptor.
|
|
|
|
|
* The ExplodedSmp can be created with the {@link #create(java.nio.file.Path)}
|
|
|
|
|
* method.
|
2014-07-13 09:47:14 +02:00
|
|
|
*
|
|
|
|
|
* @author Sebastian Sdorra
|
|
|
|
|
*/
|
2020-01-31 12:27:02 +01:00
|
|
|
public final class ExplodedSmp
|
2014-07-13 09:47:14 +02:00
|
|
|
{
|
|
|
|
|
|
2019-01-10 12:09:07 +01:00
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ExplodedSmp.class);
|
|
|
|
|
|
2014-07-13 09:47:14 +02:00
|
|
|
/**
|
|
|
|
|
* Constructs ...
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param path
|
2014-07-13 13:47:35 +02:00
|
|
|
* @param plugin
|
2014-07-13 09:47:14 +02:00
|
|
|
*/
|
2019-08-20 08:05:41 +02:00
|
|
|
ExplodedSmp(Path path, InstalledPluginDescriptor plugin)
|
2014-07-13 09:47:14 +02:00
|
|
|
{
|
2019-01-10 12:09:07 +01:00
|
|
|
logger.trace("create exploded scm for plugin {} and dependencies {}", plugin.getInformation().getName(), plugin.getDependencies());
|
2014-07-13 09:47:14 +02:00
|
|
|
this.path = path;
|
2014-07-13 13:47:35 +02:00
|
|
|
this.plugin = plugin;
|
2014-07-13 09:47:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//~--- methods --------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/**
|
2014-10-10 21:26:47 +02:00
|
|
|
* Creates a new ExplodedSmp object.
|
2014-07-13 09:47:14 +02:00
|
|
|
*
|
|
|
|
|
*
|
2014-10-10 21:26:47 +02:00
|
|
|
* @param directory directory containing an extracted SCM-Manager plugin.
|
2014-07-13 09:47:14 +02:00
|
|
|
*
|
2014-10-10 21:26:47 +02:00
|
|
|
* @return ExplodedSmp object
|
2014-07-13 09:47:14 +02:00
|
|
|
*
|
2014-10-10 21:26:47 +02:00
|
|
|
* @throws PluginException if the path does not contain an plugin descriptor
|
|
|
|
|
* or the plugin descriptor could not be parsed
|
2014-07-13 09:47:14 +02:00
|
|
|
*/
|
2014-10-10 21:26:47 +02:00
|
|
|
public static ExplodedSmp create(Path directory)
|
2014-07-13 09:47:14 +02:00
|
|
|
{
|
2014-07-13 13:47:35 +02:00
|
|
|
Path desc = directory.resolve(PluginConstants.FILE_DESCRIPTOR);
|
2014-07-13 09:47:14 +02:00
|
|
|
|
2014-07-13 13:47:35 +02:00
|
|
|
return new ExplodedSmp(directory, Plugins.parsePluginDescriptor(desc));
|
2014-07-13 09:47:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//~--- get methods ----------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/**
|
2014-10-10 21:26:47 +02:00
|
|
|
* Returns the path to the plugin directory.
|
2014-07-13 09:47:14 +02:00
|
|
|
*
|
|
|
|
|
*
|
2014-10-10 21:26:47 +02:00
|
|
|
* @return to plugin directory
|
2014-07-13 09:47:14 +02:00
|
|
|
*/
|
|
|
|
|
public Path getPath()
|
|
|
|
|
{
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-10-10 21:26:47 +02:00
|
|
|
* Returns parsed plugin descriptor.
|
2014-07-13 09:47:14 +02:00
|
|
|
*
|
|
|
|
|
*
|
2014-10-10 21:26:47 +02:00
|
|
|
* @return plugin descriptor
|
2014-07-13 09:47:14 +02:00
|
|
|
*/
|
2019-08-20 08:05:41 +02:00
|
|
|
public InstalledPluginDescriptor getPlugin()
|
2014-07-13 09:47:14 +02:00
|
|
|
{
|
2014-07-13 13:47:35 +02:00
|
|
|
return plugin;
|
2014-07-13 09:47:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//~--- inner classes --------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/**
|
2014-10-10 21:26:47 +02:00
|
|
|
* Transforms {@link Path} to {@link ExplodedSmp}.
|
2014-07-13 09:47:14 +02:00
|
|
|
*/
|
|
|
|
|
public static class PathTransformer implements Function<Path, ExplodedSmp>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
2014-10-10 21:26:47 +02:00
|
|
|
* Transforms {@link Path} to {@link ExplodedSmp}. The path must contain an
|
|
|
|
|
* extracted SCM-Manager plugin.
|
2014-07-13 09:47:14 +02:00
|
|
|
*
|
|
|
|
|
*
|
2014-10-10 21:26:47 +02:00
|
|
|
* @param directory directory containing exploded plugin
|
2014-07-13 09:47:14 +02:00
|
|
|
*
|
2014-10-10 21:26:47 +02:00
|
|
|
* @return exploded smp object
|
|
|
|
|
*
|
|
|
|
|
* @throws PluginException if the path does not contain an extracted
|
|
|
|
|
* SCM-Manager plugin.
|
2014-07-13 09:47:14 +02:00
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public ExplodedSmp apply(Path directory)
|
|
|
|
|
{
|
2014-10-10 21:26:47 +02:00
|
|
|
return ExplodedSmp.create(directory);
|
2014-07-13 09:47:14 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//~--- fields ---------------------------------------------------------------
|
|
|
|
|
|
2014-10-10 21:26:47 +02:00
|
|
|
/** directory */
|
2014-07-13 09:47:14 +02:00
|
|
|
private final Path path;
|
|
|
|
|
|
2014-10-10 21:26:47 +02:00
|
|
|
/** plugin object */
|
2019-08-20 08:05:41 +02:00
|
|
|
private final InstalledPluginDescriptor plugin;
|
2014-07-13 09:47:14 +02:00
|
|
|
}
|