From dc6ceea570e7a937da802708ab4d94f998e4760d Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Wed, 8 May 2019 17:17:05 +0100 Subject: [PATCH] JAL-3247 JAL-3254 Automatically creating correct file association inserts for Info.plist and install4j installer --- utils/install4j/auto_file_associations.pl | 128 ++++-- .../file_associations_auto-Info_plist.xml | 200 ++++++--- .../install4j/file_associations_auto-install4j.xml | 452 ++++++++++++++------ .../file_associations_template-Info_plist.xml | 4 +- .../file_associations_template-install4j.xml | 4 +- 5 files changed, 574 insertions(+), 214 deletions(-) diff --git a/utils/install4j/auto_file_associations.pl b/utils/install4j/auto_file_associations.pl index b46e274..69c07bf 100755 --- a/utils/install4j/auto_file_associations.pl +++ b/utils/install4j/auto_file_associations.pl @@ -5,6 +5,40 @@ use strict; my $fileformats = $ARGV[0]; $fileformats = "./src/jalview/io/FileFormats.java" unless $fileformats; +# default mimetype will be text/x-$shortname +# TODO: find an actual extension for mat, see JAL-Xxxxx for outstanding issues too +# TODO: look up standard mime type used for BLASTfmt matrices, etc +my $mimetypes = { + rnaml => "application/rnaml+xml", + biojson => "application/x-jalview-biojson+json", + jnet => "application/x-jalview-jnet+text", + features => "application/x-jalview-features+text", + scorematrix => "application/x-jalview-scorematrix+text", + pdb => "chemical/x-pdb", + mmcif => "chemical/x-cif", + mmcif2 => "chemical/x-mcif", + jalview => "application/x-jalview+xml+zip", + jvl => "application/x-jalview-jvl+text", + annotations => "application/x-jalview-annotations+text", +}; + +my @dontaddshortname = qw(features json); +my @dontaddextension = qw(html xml json jar mfa fastq); +my $add_associations = { + biojson => {shortname=>"biojson",name=>"BioJSON",extensions=>["biojson"]}, + gff2 => {shortname=>"gff2",name=>"Generic Features Format v2",extensions=>["gff2"]}, + gff3 => {shortname=>"gff3",name=>"Generic Features Format v3",extensions=>["gff3"]}, + features => {shortname=>"features",name=>"Jalview Features",extensions=>["features","jvfeatures"]}, + annotations => {shortname=>"annotations",name=>"Jalview Annotations",extensions=>["annotations","jvannotations"]}, + mmcif2 => {shortname=>"mmcif2",name=>"mmCIF",extensions=>["mcif","mmcif"]}, + jvl => {shortname=>"jvl",name=>"Jalview Version Locator",extensions=>["jvl"],iconfile=>"Jalview-Version-Locator"}, + jnet => {shortname=>"jnet",name=>"JnetFile",extensions=>["concise","jnet"]}, + scorematrix => {shortname=>"scorematrix",name=>"Substitution Matrix",extensions=>["mat"]}, +}; +my $add_extensions = { + blc => ["blc"], +}; + my $mactemplatefile = "file_associations_template-Info_plist.xml"; my $i4jtemplatefile = "file_associations_template-install4j.xml"; my $mactemplate; @@ -33,49 +67,87 @@ open(IA,">$i4jautofile") or die ("Could not open '$i4jautofile' for writing"); open(IN, "<$fileformats") or die ("Could not open '$fileformats' for reading"); my $id = 10000; +my $file_associations = {}; while(my $line = ) { $line =~ s/\s+/ /g; $line =~ s/(^ | $)//g; if ($line =~ m/^(\w+) ?\( ?"([^"]*)" ?, ?"([^"]*)" ?, ?(true|false) ?, ?(true|false) ?\)$/i) { my $shortname = lc($1); + next if (grep($_ eq $shortname, @dontaddshortname)); my $name = $2; my $extensions = $3; $extensions =~ s/\s+//g; - my @extensions = split(m/,/,$extensions); - #warn("LINE: $line\nFound extensions '".join("', '", @extensions)."' for $name Files ($shortname)'n"); - - my $macentry = $mactemplate; - my $i4jentry = $i4jtemplate; - - $macentry =~ s/\$\$NAME\$\$/$name/g; - $macentry =~ s/\$\$SHORTNAME\$\$/$shortname/g; - - $i4jentry =~ s/\$\$NAME\$\$/$name/g; - $i4jentry =~ s/\$\$SHORTNAME\$\$/$shortname/g; - - while ($macentry =~ m/\$\$([^\$]*)EXTENSIONS([^\$]*)\$\$/) { - my $pre = $1; - my $post = $2; - my $macextensions; - for my $ext (@extensions) { - $macextensions .= $pre.$ext.$post; - } - $macentry =~ s/\$\$${pre}EXTENSIONS${post}\$\$/$macextensions/g; + my @possextensions = split(m/,/,$extensions); + my @extensions; + my $addext = $add_extensions->{$shortname}; + if (ref($addext) eq "ARRAY") { + push(@possextensions, @$addext); + } + for my $possext (@possextensions) { + next if grep($_ eq $possext, @extensions); + next if grep($_ eq $possext, @dontaddextension); + push(@extensions,$possext); } - print MA $macentry; + next unless scalar(@extensions); + $file_associations->{$shortname} = { + shortname => $shortname, + name => $name, + extensions => \@extensions + }; + } +} +close(IN); - for my $ext (@extensions) { - my $i4jextentry = $i4jentry; - $i4jextentry =~ s/\$\$EXTENSION\$\$/$ext/g; - $i4jextentry =~ s/\$\$ID\$\$/$id/g; - $id++; +my %all_associations = (%$file_associations, %$add_associations); + +for my $fa (sort keys %all_associations) { + my $shortname = $fa; + my $a = $all_associations{$fa}; + my $name = $a->{name}; + my $extensions = $a->{extensions}; + my $mimetype = $mimetypes->{$shortname}; + $mimetype = "text/x-$shortname" unless $mimetype; + + my $iconfile = $a->{iconfile}; + $iconfile = "Jalview-File" unless $iconfile; - print IA $i4jextentry; + my @extensions = @$extensions; + #warn("LINE: $line\nFound extensions '".join("', '", @extensions)."' for $name Files ($shortname)'n"); + + my $macentry = $mactemplate; + my $i4jentry = $i4jtemplate; + + $macentry =~ s/\$\$NAME\$\$/$name/g; + $macentry =~ s/\$\$SHORTNAME\$\$/$shortname/g; + $macentry =~ s/\$\$MIMETYPE\$\$/$mimetype/g; + $macentry =~ s/\$\$ICONFILE\$\$/$iconfile/g; + + $i4jentry =~ s/\$\$NAME\$\$/$name/g; + $i4jentry =~ s/\$\$SHORTNAME\$\$/$shortname/g; + $i4jentry =~ s/\$\$MIMETYPE\$\$/$mimetype/g; + $i4jentry =~ s/\$\$ICONFILE\$\$/$iconfile/g; + + while ($macentry =~ m/\$\$([^\$]*)EXTENSIONS([^\$]*)\$\$/) { + my $pre = $1; + my $post = $2; + my $macextensions; + for my $ext (@extensions) { + $macextensions .= $pre.$ext.$post; } + $macentry =~ s/\$\$${pre}EXTENSIONS${post}\$\$/$macextensions/g; + } + print MA $macentry; + + for my $ext (@extensions) { + my $i4jextentry = $i4jentry; + $i4jextentry =~ s/\$\$EXTENSION\$\$/$ext/g; + $i4jextentry =~ s/\$\$ID\$\$/$id/g; + $id++; + print IA $i4jextentry; } } -close(IN); + close(IA); print MA "\n"; close(MA); diff --git a/utils/install4j/file_associations_auto-Info_plist.xml b/utils/install4j/file_associations_auto-Info_plist.xml index f799885..8be95e6 100644 --- a/utils/install4j/file_associations_auto-Info_plist.xml +++ b/utils/install4j/file_associations_auto-Info_plist.xml @@ -4,20 +4,17 @@ CFBundleTypeExtensions -fa -fasta -mfa -fastq +amsa CFBundleTypeName -Fasta File +AMSA File CFBundleTypeIconFile Jalview-File.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-fasta +text/x-amsa LSIsAppleDefaultForType @@ -26,17 +23,18 @@ CFBundleTypeExtensions -pfam +annotations +jvannotations CFBundleTypeName -PFAM File +Jalview Annotations File CFBundleTypeIconFile Jalview-File.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-pfam +application/x-jalview-annotations+text LSIsAppleDefaultForType @@ -45,18 +43,17 @@ CFBundleTypeExtensions -sto -stk +biojson CFBundleTypeName -Stockholm File +BioJSON File CFBundleTypeIconFile Jalview-File.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-stockholm +application/x-jalview-biojson+json LSIsAppleDefaultForType @@ -65,17 +62,18 @@ CFBundleTypeExtensions -pir +BLC +blc CFBundleTypeName -PIR File +BLC File CFBundleTypeIconFile Jalview-File.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-pir +text/x-blc LSIsAppleDefaultForType @@ -84,17 +82,17 @@ CFBundleTypeExtensions -BLC +aln CFBundleTypeName -BLC File +Clustal File CFBundleTypeIconFile Jalview-File.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-blc +text/x-clustal LSIsAppleDefaultForType @@ -103,17 +101,18 @@ CFBundleTypeExtensions -amsa +fa +fasta CFBundleTypeName -AMSA File +Fasta File CFBundleTypeIconFile Jalview-File.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-amsa +text/x-fasta LSIsAppleDefaultForType @@ -122,17 +121,18 @@ CFBundleTypeExtensions -html +features +jvfeatures CFBundleTypeName -HTML File +Jalview Features File CFBundleTypeIconFile Jalview-File.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-html +application/x-jalview-features+text LSIsAppleDefaultForType @@ -141,18 +141,17 @@ CFBundleTypeExtensions -xml -rnaml +gff2 CFBundleTypeName -RNAML File +Generic Features Format v2 File CFBundleTypeIconFile Jalview-File.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-rnaml +text/x-gff2 LSIsAppleDefaultForType @@ -161,17 +160,17 @@ CFBundleTypeExtensions -json +gff3 CFBundleTypeName -JSON File +Generic Features Format v3 File CFBundleTypeIconFile Jalview-File.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-json +text/x-gff3 LSIsAppleDefaultForType @@ -180,17 +179,95 @@ CFBundleTypeExtensions -pileup +jvp CFBundleTypeName -PileUp File +Jalview File +CFBundleTypeIconFile +Jalview-File.icns +CFBundleTypeRole +Editor +CFBundleTypeMIMETypes + +application/x-jalview+xml+zip + +LSIsAppleDefaultForType + + + + +CFBundleTypeExtensions + +concise +jnet + +CFBundleTypeName +JnetFile File +CFBundleTypeIconFile +Jalview-File.icns +CFBundleTypeRole +Editor +CFBundleTypeMIMETypes + +application/x-jalview-jnet+text + +LSIsAppleDefaultForType + + + + +CFBundleTypeExtensions + +jvl + +CFBundleTypeName +Jalview Version Locator File +CFBundleTypeIconFile +Jalview-Version-Locator.icns +CFBundleTypeRole +Editor +CFBundleTypeMIMETypes + +application/x-jalview-jvl+text + +LSIsAppleDefaultForType + + + + +CFBundleTypeExtensions + +cif + +CFBundleTypeName +mmCIF File +CFBundleTypeIconFile +Jalview-File.icns +CFBundleTypeRole +Editor +CFBundleTypeMIMETypes + +chemical/x-cif + +LSIsAppleDefaultForType + + + + +CFBundleTypeExtensions + +mcif +mmcif + +CFBundleTypeName +mmCIF File CFBundleTypeIconFile Jalview-File.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-pileup +chemical/x-mcif LSIsAppleDefaultForType @@ -209,7 +286,7 @@ Editor CFBundleTypeMIMETypes -application/x-jalview-msf +text/x-msf LSIsAppleDefaultForType @@ -218,17 +295,18 @@ CFBundleTypeExtensions -aln +pdb +ent CFBundleTypeName -Clustal File +PDB File CFBundleTypeIconFile Jalview-File.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-clustal +chemical/x-pdb LSIsAppleDefaultForType @@ -237,17 +315,17 @@ CFBundleTypeExtensions -phy +pfam CFBundleTypeName -PHYLIP File +PFAM File CFBundleTypeIconFile Jalview-File.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-phylip +text/x-pfam LSIsAppleDefaultForType @@ -256,16 +334,17 @@ CFBundleTypeExtensions +phy CFBundleTypeName -JnetFile File +PHYLIP File CFBundleTypeIconFile Jalview-File.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-jnet +text/x-phylip LSIsAppleDefaultForType @@ -274,18 +353,17 @@ CFBundleTypeExtensions -gff2 -gff3 +pileup CFBundleTypeName -GFF or Jalview features File +PileUp File CFBundleTypeIconFile Jalview-File.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-features +text/x-pileup LSIsAppleDefaultForType @@ -294,16 +372,17 @@ CFBundleTypeExtensions +pir CFBundleTypeName -Substitution matrix File +PIR File CFBundleTypeIconFile Jalview-File.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-scorematrix +text/x-pir LSIsAppleDefaultForType @@ -312,18 +391,17 @@ CFBundleTypeExtensions -pdb -ent +rnaml CFBundleTypeName -PDB File +RNAML File CFBundleTypeIconFile Jalview-File.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-pdb +application/rnaml+xml LSIsAppleDefaultForType @@ -332,17 +410,17 @@ CFBundleTypeExtensions -cif +mat CFBundleTypeName -mmCIF File +Substitution Matrix File CFBundleTypeIconFile Jalview-File.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-mmcif +application/x-jalview-scorematrix+text LSIsAppleDefaultForType @@ -351,18 +429,18 @@ CFBundleTypeExtensions -jvp -jar +sto +stk CFBundleTypeName -Jalview File +Stockholm File CFBundleTypeIconFile Jalview-File.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-jalview +text/x-stockholm LSIsAppleDefaultForType diff --git a/utils/install4j/file_associations_auto-install4j.xml b/utils/install4j/file_associations_auto-install4j.xml index d82eff3..c7b07ee 100644 --- a/utils/install4j/file_associations_auto-install4j.xml +++ b/utils/install4j/file_associations_auto-install4j.xml @@ -1,19 +1,19 @@ - + - Fasta File + AMSA File - fa + amsa 737 - ./Jalview-File.icns + Jalview-File.icns @@ -24,7 +24,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -33,22 +33,22 @@ - + - Fasta File + Jalview Annotations File - fasta + annotations 737 - ./Jalview-File.icns + Jalview-File.icns @@ -59,7 +59,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -68,22 +68,22 @@ - + - Fasta File + Jalview Annotations File - mfa + jvannotations 737 - ./Jalview-File.icns + Jalview-File.icns @@ -94,7 +94,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -103,22 +103,22 @@ - + - Fasta File + BioJSON File - fastq + biojson 737 - ./Jalview-File.icns + Jalview-File.icns @@ -129,7 +129,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -138,22 +138,22 @@ - + - PFAM File + BLC File - pfam + BLC 737 - ./Jalview-File.icns + Jalview-File.icns @@ -164,7 +164,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -173,22 +173,22 @@ - + - Stockholm File + BLC File - sto + blc 737 - ./Jalview-File.icns + Jalview-File.icns @@ -199,7 +199,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -208,22 +208,22 @@ - + - Stockholm File + Clustal File - stk + aln 737 - ./Jalview-File.icns + Jalview-File.icns @@ -234,7 +234,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -243,22 +243,22 @@ - + - PIR File + Fasta File - pir + fa 737 - ./Jalview-File.icns + Jalview-File.icns @@ -269,7 +269,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -278,22 +278,22 @@ - + - BLC File + Fasta File - BLC + fasta 737 - ./Jalview-File.icns + Jalview-File.icns @@ -304,7 +304,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -313,22 +313,22 @@ - + - AMSA File + Jalview Features File - amsa + features 737 - ./Jalview-File.icns + Jalview-File.icns @@ -339,7 +339,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -348,22 +348,22 @@ - + - HTML File + Jalview Features File - html + jvfeatures 737 - ./Jalview-File.icns + Jalview-File.icns @@ -374,7 +374,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -383,22 +383,22 @@ - + - RNAML File + Generic Features Format v2 File - xml + gff2 737 - ./Jalview-File.icns + Jalview-File.icns @@ -409,7 +409,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -418,22 +418,22 @@ - + - RNAML File + Generic Features Format v3 File - rnaml + gff3 737 - ./Jalview-File.icns + Jalview-File.icns @@ -444,7 +444,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -453,22 +453,22 @@ - + - JSON File + Jalview File - json + jvp 737 - ./Jalview-File.icns + Jalview-File.icns @@ -479,7 +479,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -488,22 +488,22 @@ - + - PileUp File + JnetFile File - pileup + concise 737 - ./Jalview-File.icns + Jalview-File.icns @@ -514,7 +514,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -523,22 +523,22 @@ - + - MSF File + JnetFile File - msf + jnet 737 - ./Jalview-File.icns + Jalview-File.icns @@ -549,7 +549,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -558,22 +558,22 @@ - + - Clustal File + Jalview Version Locator File - aln + jvl 737 - ./Jalview-File.icns + Jalview-Version-Locator.icns @@ -584,7 +584,7 @@ - ./Jalview-File.ico + Jalview-Version-Locator.ico @@ -593,22 +593,22 @@ - + - PHYLIP File + mmCIF File - phy + cif 737 - ./Jalview-File.icns + Jalview-File.icns @@ -619,7 +619,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -628,22 +628,22 @@ - + - GFF or Jalview features File + mmCIF File - gff2 + mcif 737 - ./Jalview-File.icns + Jalview-File.icns @@ -654,7 +654,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -663,22 +663,57 @@ - + - GFF or Jalview features File + mmCIF File - gff3 + mmcif + + + 737 + + + + Jalview-File.icns + + + + + com.install4j.runtime.beans.actions.desktop.MacAssociationRole + EDITOR + + + + + Jalview-File.ico + + + + + + + + + + + + + + MSF File + + + msf 737 - ./Jalview-File.icns + Jalview-File.icns @@ -689,7 +724,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -698,7 +733,7 @@ - + @@ -713,7 +748,7 @@ - ./Jalview-File.icns + Jalview-File.icns @@ -724,7 +759,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -733,7 +768,7 @@ - + @@ -748,7 +783,7 @@ - ./Jalview-File.icns + Jalview-File.icns @@ -759,7 +794,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -768,22 +803,22 @@ - + - mmCIF File + PFAM File - cif + pfam 737 - ./Jalview-File.icns + Jalview-File.icns @@ -794,7 +829,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -803,22 +838,22 @@ - + - Jalview File + PHYLIP File - jvp + phy 737 - ./Jalview-File.icns + Jalview-File.icns @@ -829,7 +864,7 @@ - ./Jalview-File.ico + Jalview-File.ico @@ -838,22 +873,197 @@ - + - Jalview File + PileUp File - jar + pileup + + + 737 + + + + Jalview-File.icns + + + + + com.install4j.runtime.beans.actions.desktop.MacAssociationRole + EDITOR + + + + + Jalview-File.ico + + + + + + + + + + + + + + PIR File + + + pir + + + 737 + + + + Jalview-File.icns + + + + + com.install4j.runtime.beans.actions.desktop.MacAssociationRole + EDITOR + + + + + Jalview-File.ico + + + + + + + + + + + + + + RNAML File + + + rnaml + + + 737 + + + + Jalview-File.icns + + + + + com.install4j.runtime.beans.actions.desktop.MacAssociationRole + EDITOR + + + + + Jalview-File.ico + + + + + + + + + + + + + + Substitution Matrix File + + + mat + + + 737 + + + + Jalview-File.icns + + + + + com.install4j.runtime.beans.actions.desktop.MacAssociationRole + EDITOR + + + + + Jalview-File.ico + + + + + + + + + + + + + + Stockholm File + + + sto + + + 737 + + + + Jalview-File.icns + + + + + com.install4j.runtime.beans.actions.desktop.MacAssociationRole + EDITOR + + + + + Jalview-File.ico + + + + + + + + + + + + + + Stockholm File + + + stk 737 - ./Jalview-File.icns + Jalview-File.icns @@ -864,7 +1074,7 @@ - ./Jalview-File.ico + Jalview-File.ico diff --git a/utils/install4j/file_associations_template-Info_plist.xml b/utils/install4j/file_associations_template-Info_plist.xml index 66720a1..7fa4fed 100644 --- a/utils/install4j/file_associations_template-Info_plist.xml +++ b/utils/install4j/file_associations_template-Info_plist.xml @@ -6,12 +6,12 @@ $$ CFBundleTypeName $$NAME$$ File CFBundleTypeIconFile -Jalview-File.icns +$$ICONFILE$$.icns CFBundleTypeRole Editor CFBundleTypeMIMETypes -application/x-jalview-$$SHORTNAME$$ +$$MIMETYPE$$ LSIsAppleDefaultForType diff --git a/utils/install4j/file_associations_template-install4j.xml b/utils/install4j/file_associations_template-install4j.xml index 96eff1e..697029a 100644 --- a/utils/install4j/file_associations_template-install4j.xml +++ b/utils/install4j/file_associations_template-install4j.xml @@ -13,7 +13,7 @@ - ./Jalview-File.icns + $$ICONFILE$$.icns @@ -24,7 +24,7 @@ - ./Jalview-File.ico + $$ICONFILE$$.ico -- 1.7.10.2