@@ -0,0 +1,3445 @@
+/*%0A * Copyright (C) 2012-present the original author or authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.pf4j.plugin;%0A%0Aimport org.pf4j.ManifestPluginDescriptorFinder;%0A%0Aimport java.io.FileOutputStream;%0Aimport java.io.IOException;%0Aimport java.nio.file.Path;%0Aimport java.util.Map;%0Aimport java.util.Set;%0Aimport java.util.jar.Attributes;%0Aimport java.util.jar.JarOutputStream;%0Aimport java.util.jar.Manifest;%0A%0A/**%0A /**%0A * Represents a plugin %7B@code jar%7D file.%0A * The %7B@code MANIFEST.MF%7D file is created on the fly from the information supplied in %7B@link Builder%7D.%0A *%0A * @author Decebal Suiu%0A */%0Apublic class PluginJar %7B%0A%0A    private final Path path;%0A    private final String pluginId;%0A    private final String pluginVersion;%0A%0A    protected PluginJar(Builder builder) %7B%0A        this.path = builder.path;%0A        this.pluginId = builder.pluginId;%0A        this.pluginVersion = builder.pluginVersion;%0A    %7D%0A%0A    public Path path() %7B%0A        return path;%0A    %7D%0A%0A    public String pluginId() %7B%0A        return pluginId;%0A    %7D%0A%0A    public String pluginVersion() %7B%0A        return pluginVersion;%0A    %7D%0A%0A    public static class Builder %7B%0A%0A        private final Path path;%0A        private final String pluginId;%0A%0A        private String pluginVersion;%0A        private Map%3CString, String%3E attributes;%0A%0A        public Builder(Path path, String pluginId) %7B%0A            this.path = path;%0A            this.pluginId = pluginId;%0A        %7D%0A%0A        public Builder pluginVersion(String pluginVersion) %7B%0A            this.pluginVersion = pluginVersion;%0A%0A            return this;%0A        %7D%0A%0A        /**%0A         * Add extra attributes to the %7B@code manifest%7D file.%0A         */%0A        public Builder attributes(Map%3CString, String%3E attributes) %7B%0A            this.attributes = attributes;%0A%0A            return this;%0A        %7D%0A%0A        public PluginJar build() throws IOException %7B%0A            createManifestFile();%0A%0A            return new PluginJar(this);%0A        %7D%0A%0A        protected void createManifestFile() throws IOException %7B%0A            Manifest manifest = new Manifest();%0A            Attributes attrs = manifest.getMainAttributes();%0A            attrs.put(Attributes.Name.MANIFEST_VERSION, %221.0.0%22);%0A            attrs.put(new Attributes.Name(ManifestPluginDescriptorFinder.PLUGIN_ID), pluginId);%0A            attrs.put(new Attributes.Name(ManifestPluginDescriptorFinder.PLUGIN_VERSION), pluginVersion);%0A            attrs.put(new Attributes.Name(ManifestPluginDescriptorFinder.PLUGIN_CLASS), %22org.pf4j.plugin.TestPlugin%22);%0A            if (attributes != null) %7B%0A                Set%3CString%3E names = attributes.keySet();%0A                for (String name : names) %7B%0A                    attrs.put(new Attributes.Name(name), attributes.get(name));%0A                %7D%0A            %7D%0A%0A            JarOutputStream outputStream = new JarOutputStream(new FileOutputStream(path.toFile()), manifest);%0A            outputStream.close();%0A        %7D%0A%0A    %7D%0A%0A%7D%0A

Add PluginJar