Contenu | Rechercher | Menus

Annonce

Le forum rencontre en ce moment quelques soucis de charge, il est possible qu'une erreur soit affichée quand vous postez un message, ne rechargez pas la page au risque de poster une seconde fois votre message

Si vous rencontrez des soucis à rester connecté sur le forum (ou si vous avez perdu votre mot de passe) déconnectez-vous et reconnectez-vous depuis cette page, en cochant la case "Me connecter automatiquement lors de mes prochaines visites".

#1 Le 26/05/2012, à 12:00

[Résolu] aide pour l'écriture d'un script (génération de fichiers psf)

Bonjour à tous,
  je suis en train d'écrire un script pour générer un fichier psf (Project Set File) (comme celui-ci par exemple). Ce type de fichiers permet de télécharger facilement un ensemble de projet depuis un SVN dans le workspace d'Eclipse. Celui visible dans mon lien permet de faire 2 choses :

  1. télécharger des projets

  2. les ranger par "thèmes" dans des "WorkingSet"

Mon script actuel :

#!/bin/bash
# Copyright (c) 2012 CEA LIST.
#All rights reserved. This program and the accompanying materials
#are made available under the terms of the Eclipse Public License v1.0
#which accompanies this distribution, and is available at
#http://www.eclipse.org/legal/epl-v10.html
#

# This script downloads the folders which contains a file .project from a repository and create the psf file to download it using Eclipse
psfName='extraplugins.psf'
beginningString='<project reference="0.9.3,'
endString='"/>'
endProvider='</provider>'
beginWorkingSet='<workingSets editPageId="org.eclipse.jdt.ui.JavaWorkingSetPage"'
endWorkingSet='</workingSets>'


#cd /tmp
mkdir svn_psf
cd svn_psf
#the wget should be parameterized to download others folders
wget -r -np -A .project http://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/extraplugins/

#remove the existing file
rm -f $psfName

#begin the XML file
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>">>$psfName
echo "<psf version=\"2.0\">">>$psfName
echo "<provider id=\"org.tigris.subversion.subclipse.core.svnnature\">">>$psfName


#remove all empty folders!
find -depth -type d -empty -exec rmdir {} \;


#---------------------------------------------------------------------fill the file with the plugin to download
#see http://forum.ubuntu-fr.org/post.php?tid=932861 for FOLDERNAME
for FULL_PATH_FOLDER in `find . -name ".project"`
    do
        FOLDERNAME=$(echo $FULL_PATH_FOLDER | grep -oE "[^/]*/[^/]*$" )
        echo $beginningString$FULL_PATH_FOLDER','$FOLDERNAME$endString>>$psfName
    done
echo $endProvider>>$psfName

#    .../myProjectName/.project -> .../myProjectName
sed -i "s/\/.project//g" $psfName
#add http:\ after 0.9.3,
sed -i "s/0\.9\.3,\./0\.9\.3,http:\//g" $psfName
#---------------------------------------------------------------------Create the working Set

#TODO

#---------------------------------------------------------------------end the XML file
echo "</psf>">>$psfName

J'ai réussie à générer la 1ère partie sans trop de problème, mais je butte sur la seconde (après </provider> dans cet exemple): je dois à présent :
       - récupérer récursivement tous les dossiers qui ne contiennent pas directement un fichier .project
       - j'itère ensuite sur ces dossiers :
            1/ j'ajoute la ligne suivante à mon fichier :

<workingSets editPageId="org.eclipse.jdt.ui.JavaWorkingSetPage" id="1319612372883_37" label="NOM_DU_REPERTOOIRE" name="NOM_DU_REPERTOIRE">

            2/ je recherche tous ses répertoires qui contiennent directement un fichier .project
                  pour chacun sius-répertoire j'ajoute la ligne suivante à mon fichier

<item elementID="=NOM_DU_SOUS_REPERTOIRE" factoryID="org.eclipse.jdt.ui.PersistableJavaElementFactory"/>

           3/ je ferme ma balise

</workingSets>

Cet algo devrait me donner à peut-près ce que je veux, quitte à faire un peu de regex dessus pour nettoyer ce qui pourrait être en trop...

Pour commencer, je n'arrive pas à trouver les répertoires qui ne contiennent pas directement le fichier .project. (leur répertoire fils peuvent par contre le contenir)
Pour

./dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/extraplugins/alf
./dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/extraplugins/alf/org.eclipse.papyrus.operation.editor.xtext/.project
./dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/extraplugins/alf/org.eclipse.papyrus.alf.sdk-feature/.project
./dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/extraplugins/alf/org.eclipse.papyrus.operation.editor.xtext.ui/.project

Je ne veux récupérer que

./dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/extraplugins/alf

Je ne m'en sors pas avec find, une aide serait la bienvenue.

Dernière modification par irnange (Le 06/06/2012, à 17:36)


Irnange

Hors ligne

#2 Le 26/05/2012, à 18:28

Re : [Résolu] aide pour l'écriture d'un script (génération de fichiers psf)

Salut

Sans être bien sur et à partir du dossier père :

find . ! -regex ".*\/\.project"

A tester ...


Un petit [Résolu] dans le titre quand c'est le cas !!

Hors ligne

#3 Le 27/05/2012, à 11:18

Re : [Résolu] aide pour l'écriture d'un script (génération de fichiers psf)

Merci, mais ça ne renvoie pas ce que je souhaite. Pour l'exemple plus haut, ça me retourne :

./dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/extraplugins/alf
./dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/extraplugins/alf/org.eclipse.papyrus.operation.editor.xtext
./dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/extraplugins/alf/org.eclipse.papyrus.alf.sdk-feature
./dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/extraplugins/alf/org.eclipse.papyrus.operation.editor.xtext.ui

Irnange

Hors ligne

#4 Le 06/06/2012, à 17:35

Re : [Résolu] aide pour l'écriture d'un script (génération de fichiers psf)

Après pas mal de temps, j'ai réussi à écrire mon script. Cf ci-après pour ceux que ça intéresse.

#!/bin/sh
#
#All rights reserved. This program and the accompanying materials
#are made available under the terms of the Eclipse Public License v1.0
#which accompanies this distribution, and is available at
#http://www.eclipse.org/legal/epl-v10.html
#
#this function create a psf file in $generated_psf_folder
#this function takes arguments : 
#        - the first argument is the psf file name without its extension
#        - the others arguments are the path of the repository to download 
create_psf_file(){
psf_ssh_file_name="svn_ssh_"$1".psf"
beginningString='<project reference="0.9.3,'
endString='"/>'
endProvider='</provider>'
beginWorkingSet='<workingSets editPageId="org.eclipse.jdt.ui.JavaWorkingSetPage"'
endWorkingSet='</workingSets>'
#---firstly we create the svn+ssh file
#---begin the XML file
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>">>$generated_psf_folder/$psf_ssh_file_name
echo "<psf version=\"2.0\">">>$generated_psf_folder/$psf_ssh_file_name
echo "<provider id=\"org.tigris.subversion.subclipse.core.svnnature\">">>$generated_psf_folder/$psf_ssh_file_name

#---Fill the file with the projects to download
#see http://forum.ubuntu-fr.org/post.php?tid=932861 for FOLDERNAME
for FULL_PATH_FOLDER in `find . -name ".project"`
    do
        FOLDERNAME=$(echo $FULL_PATH_FOLDER | grep -oE "[^/]*/[^/]*$" )
        echo $beginningString$FULL_PATH_FOLDER','$FOLDERNAME$endString>>$generated_psf_folder/$psf_ssh_file_name
    done
echo $endProvider>>$generated_psf_folder/$psf_ssh_file_name

#Create the Working Set

# --- all files
find .  > allFiles
# --- filter those ending with .project (and preceding folders)
grep  -B 1 ".*\/\.project" allFiles > dotProjectFiles

#--- iterate on the diff to create the WorkingSets
for folder in `diff allFiles dotProjectFiles | grep "\<" | grep ".\/dev.eclipse.org" | cut -d " " -f 2`
do
    first=1
    for subFolder in `ls $folder/*/.project 2> /dev/null` #sed "s/\/.project//g"`
    do
        if [ "$first" = 1 ];
        then
        layerName=$(echo $folder | grep -oE "[^/]*/[^/]*$")
        #replace the / by a .
        layerName=`echo ${layerName/\//.}`
           echo '<workingSets editPageId="org.eclipse.jdt.ui.JavaWorkingSetPage" id="'$workingSetId'" label="'$layerName'" name="'$layerName'">' >> $generated_psf_folder/$psf_ssh_file_name
           workingSetId=$((workingSetId +1))
           first=0;
        fi;
      subFolderName=$(echo $subFolder | grep -oE "[^/]*/[^/]*$" )    
     echo '<item elementID="='$subFolderName'" factoryID="org.eclipse.jdt.ui.PersistableJavaElementFactory"/>' >> $generated_psf_folder/$psf_ssh_file_name
    done
    if [ "$first" = 0 ] ;then
    echo '</workingSets>' >> $generated_psf_folder/$psf_ssh_file_name;
    fi
done

#---end the XML file
echo "</psf>">>$generated_psf_folder/$psf_ssh_file_name

#---correct the generated psf
#    .../myProjectName/.project -> .../myProjectName
sed -i "s/\/.project//g" $generated_psf_folder/$psf_ssh_file_name
#add http:\ after 0.9.3,
sed -i "s/0\.9\.3,\./0\.9\.3,svn+ssh:\//g" $generated_psf_folder/$psf_ssh_file_name

#---remove some created files created by this method
rm allFiles dotProjectFiles

#---copy the file to create the http file
psf_http_file_name="http_"$1".psf"
cp $generated_psf_folder/$psf_ssh_file_name $generated_psf_folder/$psf_http_file_name
$ sed -i "s/svn+ssh/http/g" $generated_psf_folder/$psf_http_file_name
}


debut=$(date +'%T')
# This script downloads the folders which contains a file .project from a repository and create the psf file to download it using Eclipse
workingSetId=0

#---create the following hierarchy : 
#$HOME/psf_workspace
#$HOME/psf_workspace/svn
#$HOME/psf_workspace/generated_psf_folder
psf_workspace=$HOME/"psf_workspace"
svn=$psf_workspace/"svn"
generated_psf_folder=$psf_workspace/"generated_psf_folder"

#the path of the folder to download
extraplugins_path="http://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/extraplugins/"
plugins_path="http://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/plugins/"
tests_path="http://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/tests/"
releng_path="http://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/releng/"
features_path="http://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/features/"
rm -R -f $psf_workspace

mkdir $psf_workspace
mkdir $generated_psf_folder


#extraplugin psf
mkdir $svn
cd $svn
wget -r -np -A .project http://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/extraplugins/
#--------remove all empty folders!
find -depth -type d -empty -exec rmdir {} \;
#--------create the psf
create_psf_file "extraplugins"
cd $psf_workspace
rm -R -f $svn

#plugin psf
mkdir $svn
cd $svn
wget -r -np -A .project http://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/plugins/
#--------remove all empty folders!
find -depth -type d -empty -exec rmdir {} \;
#--------create the psf
create_psf_file "plugins"
cd $psf_workspace
rm -R -f $svn

#tests psf
mkdir $svn
cd $svn
wget -r -np -A .project http://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/tests/
#--------remove all empty folders!
find -depth -type d -empty -exec rmdir {} \;
create_psf_file "tests"
cd $psf_workspace
rm -R -f $svn

#build psf
mkdir $svn
cd $svn
wget -r -np -A .project http://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/releng/
wget -r -np -A .project http://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/features/
#--------remove all empty folders!
find -depth -type d -empty -exec rmdir {} \;
create_psf_file "build"
cd $psf_workspace
rm -R -f $svn

fin=$(date +'%T')
echo $debut
echo $fin

Irnange

Hors ligne

Haut de page ↑