streamlet-examples/JarInfo.java
branchv_0
changeset 72 f7b9db6fc32b
child 73 1a067a217454
equal deleted inserted replaced
71:f8fe085c1c9f 72:f7b9db6fc32b
       
     1 
       
     2 /**
       
     3  * Relational pipes
       
     4  * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
       
     5  *
       
     6  * This program is free software: you can redistribute it and/or modify
       
     7  * it under the terms of the GNU General Public License as published by
       
     8  * the Free Software Foundation, version 3 of the License.
       
     9  *
       
    10  * This program is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
       
    13  * GNU General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License
       
    16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
       
    17  */
       
    18 import java.io.File;
       
    19 import java.io.IOException;
       
    20 import java.util.LinkedList;
       
    21 import java.util.List;
       
    22 import java.util.jar.JarFile;
       
    23 
       
    24 public class JarInfo extends Streamlet {
       
    25 
       
    26 	public static void main(String[] args) throws IOException {
       
    27 		JarInfo s = new JarInfo();
       
    28 		int status = s.run();
       
    29 		System.exit(status);
       
    30 
       
    31 		// TODO: return real values:
       
    32 		JarFile jar = new JarFile(new File(args[0]));
       
    33 		String mainClass = jar.getManifest() == null ? null : jar.getManifest().getMainAttributes().getValue("Main-Class");
       
    34 		System.out.println("Name:       " + jar.getName());
       
    35 		System.out.println("Comment:    " + jar.getComment());
       
    36 		System.out.println("Entries:    " + jar.stream().count());
       
    37 		System.out.println("Main class: " + mainClass);
       
    38 	}
       
    39 
       
    40 	protected List<Streamlet.AttributeMetadata> getOutputAttributesMetadata() {
       
    41 		List<Streamlet.AttributeMetadata> result = new LinkedList<>();
       
    42 		result.add(new Streamlet.AttributeMetadata("main_class", Streamlet.Type.STRING));
       
    43 		return result;
       
    44 	}
       
    45 
       
    46 	protected List<Object> getOutputAttributes() {
       
    47 		List<Object> result = new LinkedList<>();
       
    48 		result.add("TODO: main class");
       
    49 		return result;
       
    50 	}
       
    51 }