001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.util.ant.bnd;
016    
017    import java.io.File;
018    
019    import org.apache.tools.ant.BuildException;
020    import org.apache.tools.ant.Project;
021    
022    /**
023     * @author Raymond Aug??
024     */
025    public class ReleaseToRepoTask extends BaseBndTask {
026    
027            public void setDeployRepo(String name) {
028                    _deployRepo = name;
029            }
030    
031            public void setFile(File file) {
032                    _file = file;
033            }
034    
035            @Override
036            protected void doBeforeExecute() throws Exception {
037                    super.doBeforeExecute();
038    
039                    if ((_file == null) || !_file.exists() || _file.isDirectory()) {
040                            if (_file != null) {
041                                    project.log(
042                                            "file is either missing or is a directory " +
043                                                    _file.getAbsolutePath(),
044                                            Project.MSG_ERR);
045                            }
046    
047                            throw new BuildException("file is invalid");
048                    }
049            }
050    
051            @Override
052            protected void doExecute() throws Exception {
053                    aQute.bnd.build.Project bndProject = getBndProject();
054    
055                    try {
056                            if (_file.isFile() && _file.getName().endsWith(".jar")) {
057                                    if (_deployRepo != null) {
058                                            bndProject.deploy(_deployRepo, _file);
059                                    }
060                                    else {
061                                            bndProject.deploy(_file);
062                                    }
063                            }
064                            else {
065                                    project.log(
066                                            "Not a JAR file " + _file.getAbsolutePath(),
067                                            Project.MSG_ERR);
068                            }
069                    }
070                    catch (Exception e) {
071                            throw new BuildException(
072                                    e.getMessage(), e,
073                                    new org.apache.tools.ant.Location(_file.getAbsolutePath()));
074                    }
075    
076                    report(bndProject);
077    
078                    if (bndProject.getErrors().size() > 0) {
079                            throw new BuildException(
080                                    "Unable to deploy",
081                                    new org.apache.tools.ant.Location(_file.getAbsolutePath()));
082                    }
083            }
084    
085            private String _deployRepo;
086            private File _file;
087    
088    }